Home Explore Blog CI



docker

7th chunk of `content/manuals/compose/gettingstarted.md`
1e456334549786c763cbd3d54e8d5f3814ae30a45d28eb280000000100000bb0


3. Once you're done, run `docker compose down`.

## Step 7: Split up your services

Using multiple Compose files lets you customize a Compose application for different environments or workflows. This is useful for large applications that may use dozens of containers, with ownership distributed across multiple teams. 

1. In your project folder, create a new Compose file called `infra.yaml`.

2. Cut the Redis service from your `compose.yaml` file and paste it into your new `infra.yaml` file. Make sure you add the `services` top-level attribute at the top of your file. Your `infra.yaml` file should now look like this:

   ```yaml
   services:
     redis:
       image: "redis:alpine"
   ```

3. In your `compose.yaml` file, add the `include` top-level attribute along with the path to the `infra.yaml` file.

   ```yaml
   include:
      - infra.yaml
   services:
     web:
       build: .
       ports:
         - "8000:5000"
       develop:
         watch:
           - action: sync
             path: .
             target: /code
   ```

4. Run `docker compose up` to build the app with the updated Compose files, and run it. You should see the `Hello world` message in your browser. 

This is a simplified example, but it demonstrates the basic principle of `include` and how it can make it easier to modularize complex applications into sub-Compose files. For more information on `include` and working with multiple Compose files, see [Working with multiple Compose files](/manuals/compose/how-tos/multiple-compose-files/_index.md).

## Step 8: Experiment with some other commands

- If you want to run your services in the background, you can pass the `-d` flag (for "detached" mode) to `docker compose up` and use `docker compose ps` to see what is currently running:

   ```console
   $ docker compose up -d

   Starting composetest_redis_1...
   Starting composetest_web_1...

   $ docker compose ps

          Name                      Command               State           Ports         
   -------------------------------------------------------------------------------------
   composetest_redis_1   docker-entrypoint.sh redis ...   Up      6379/tcp              
   composetest_web_1     flask run                        Up      0.0.0.0:8000->5000/tcp
   ```

- Run `docker compose --help` to see other available commands.

- If you started Compose with `docker compose up -d`, stop your services once you've finished with them:

   ```console
   $ docker compose stop
   ```

- You can bring everything down, removing the containers entirely, with the `docker compose down` command. 

## Where to go next

- Try the [Sample apps with Compose](https://github.com/docker/awesome-compose)
- [Explore the full list of Compose commands](/reference/cli/docker/compose.md)
- [Explore the Compose file reference](/reference/compose-file/_index.md)
- [Check out the Learning Docker Compose video on LinkedIn Learning](https://www.linkedin.com/learning/learning-docker-compose/)

Title: Splitting Services, Other Commands, and Next Steps
Summary
This section details splitting up Docker Compose services into separate files using the `include` attribute for better modularity. It provides an example involving moving the Redis service to an `infra.yaml` file and updating the main `compose.yaml` file to include it. It further covers useful Docker Compose commands such as running services in detached mode (`-d`), viewing running services (`docker compose ps`), and stopping services (`docker compose stop`). The section concludes with suggestions for further exploration, including sample apps, the full list of Compose commands, the Compose file reference, and a LinkedIn Learning video on Docker Compose.