ENGDOCS-2140 (#20300)

* ENGDOCS-2140

* SME review

* Update content/compose/compose-application-model.md

Co-authored-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>

* Apply suggestions from code review

---------

Co-authored-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
This commit is contained in:
Allie Sadler 2024-07-08 09:36:17 +01:00 committed by GitHub
parent 615d26feaf
commit 51e5271a23
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 47 additions and 5 deletions

View File

@ -7,9 +7,9 @@ aliases:
- /compose/compose-yaml-file/
---
Docker Compose relies on a YAML configuration file, usually named `compose.yaml`.
With Docker Compose you use a YAML configuration file, known as the [Compose file](#the-compose-file), to configure your applications services, and then you create and start all the services from your configuration with the [Compose CLI](#cli).
The `compose.yaml` file follows the rules provided by the [Compose Specification](compose-file/_index.md) in how to define multi-container applications. This is the Docker Compose implementation of the formal [Compose Specification](https://github.com/compose-spec/compose-spec).
The Compose file, or `compose.yaml` file, follows the rules provided by the [Compose Specification](compose-file/_index.md) in how to define multi-container applications. This is the Docker Compose implementation of the formal [Compose Specification](https://github.com/compose-spec/compose-spec).
{{< accordion title="The Compose application model" >}}
@ -33,9 +33,7 @@ set the label `com.docker.compose.project`.
Compose offers a way for you to set a custom project name and override this name, so that the same `compose.yaml` file can be deployed twice on the same infrastructure, without changes, by just passing a distinct name.
{{< /accordion >}}
You then interact with your Compose application through the [Compose CLI](reference/_index.md). Commands such as `docker compose up` are used to start the application, while `docker compose down` stops and removes the containers.
{{< /accordion >}}
## The Compose file
@ -53,6 +51,38 @@ the expanded form. For more information, see [Working with multiple Compose file
If you want to reuse other Compose files, or factor out parts of your application model into separate Compose files, you can also use [`include`](compose-file/14-include.md). This is useful if your Compose application is dependent on another application which is managed by a different team, or needs to be shared with others.
## CLI
The Docker CLI lets you to interact with your Docker Compose applications through the `docker compose` command, and its subcommands. Using the CLI, you can manage the lifecycle of your multi-container applications defined in the `compose.yaml` file. The CLI commands enable you to start, stop, and configure your applications effortlessly.
### Key commands
To start all the services defined in your `compose.yaml` file:
```console
$ docker compose up
```
To stop and remove the running services:
```console
$ docker compose down
```
If you want to monitor the output of your running containers and debug issues, you can view the logs with:
```console
$ docker compose logs
```
To lists all the services along with their current status:
```console
$ docker compose ps
```
For a full list of all the Compose CLI commands, see the [reference documentation](../reference/cli/docker/compose/_index.md).
## Illustrative example
The following example illustrates the Compose concepts outlined above. The example is non-normative.
@ -116,6 +146,18 @@ networks:
back-tier: {}
```
The `docker compose up` command starts the `frontend` and `backend` services, create the necessary networks and volumes, and injects the configuration and secret into the frontend service.
`docker compose ps` provides a snapshot of the current state of your services, making it easy to see which containers are running, their status, and the ports they are using:
```text
$ docker compose ps
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
example-frontend-1 example/webapp "nginx -g 'daemon of…" frontend 2 minutes ago Up 2 minutes 0.0.0.0:443->8043/tcp
example-backend-1 example/database "docker-entrypoint.s…" backend 2 minutes ago Up 2 minutes
```
## What's next
- [Quickstart](gettingstarted.md)