Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit dbabfe9

Browse files
authored
Merge pull request #1416 from docker/docs
reference documentation
2 parents b6df84f + 3271801 commit dbabfe9

37 files changed

+540
-18
lines changed

docs/reference/compose.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
2+
3+
## Description
4+
5+
You can use compose subcommand, `docker compose [-f <arg>...] [options] [COMMAND] [ARGS...]`, to build and manage
6+
multiple services in Docker containers.
7+
8+
### Use `-f` to specify name and path of one or more Compose files
9+
Use the `-f` flag to specify the location of a Compose configuration file.
10+
11+
#### Specifying multiple Compose files
12+
You can supply multiple `-f` configuration files. When you supply multiple files, Compose combines them into a single
13+
configuration. Compose builds the configuration in the order you supply the files. Subsequent files override and add
14+
to their predecessors.
15+
16+
For example, consider this command line:
17+
18+
```
19+
$ docker-compose -f docker-compose.yml -f docker-compose.admin.yml run backup_db
20+
```
21+
The `docker-compose.yml` file might specify a `webapp` service.
22+
23+
```yaml
24+
services:
25+
webapp:
26+
image: examples/web
27+
ports:
28+
- "8000:8000"
29+
volumes:
30+
- "/data"
31+
```
32+
If the `docker-compose.admin.yml` also specifies this same service, any matching fields override the previous file.
33+
New values, add to the `webapp` service configuration.
34+
35+
```yaml
36+
services:
37+
webapp:
38+
build: .
39+
environment:
40+
- DEBUG=1
41+
```
42+
43+
When you use multiple Compose files, all paths in the files are relative to the first configuration file specified
44+
with `-f`. You can use the `--project-directory` option to override this base path.
45+
46+
Use a `-f` with `-` (dash) as the filename to read the configuration from stdin. When stdin is used all paths in the
47+
configuration are relative to the current working directory.
48+
49+
The `-f` flag is optional. If you don’t provide this flag on the command line, Compose traverses the working directory
50+
and its parent directories looking for a `compose.yaml` or `docker-compose.yaml` file.
51+
52+
#### Specifying a path to a single Compose file
53+
You can use the `-f` flag to specify a path to a Compose file that is not located in the current directory, either
54+
from the command line or by setting up a `COMPOSE_FILE` environment variable in your shell or in an environment file.
55+
56+
For an example of using the `-f` option at the command line, suppose you are running the Compose Rails sample, and
57+
have a `compose.yaml` file in a directory called `sandbox/rails`. You can use a command like `docker compose pull` to
58+
get the postgres image for the db service from anywhere by using the `-f` flag as follows:
59+
```
60+
docker compose -f ~/sandbox/rails/compose.yaml pull db
61+
```
62+
63+
### Use `-p` to specify a project name
64+
65+
Each configuration has a project name. If you supply a `-p` flag, you can specify a project name. If you don’t
66+
specify the flag, Compose uses the current directory name.
67+
Project name can also be set by `COMPOSE_PROJECT_NAME` environment variable.
68+
69+
Most compose subcommand can be ran without a compose file, just passing
70+
project name to retrieve the relevant resources.
71+
72+
```
73+
$ docker compose -p my_project ps -a
74+
NAME SERVICE STATUS PORTS
75+
my_project_demo_1 demo running
76+
77+
$ docker compose -p my_project logs
78+
demo_1 | PING localhost (127.0.0.1): 56 data bytes
79+
demo_1 | 64 bytes from 127.0.0.1: seq=0 ttl=64 time=0.095 ms
80+
```
81+
82+
### Use profiles to enable optional services
83+
84+
Use `--profile` to specify one or more active profiles
85+
Calling `docker compose --profile frontend up` will start the services with the profile `frontend` and services
86+
without any specified profiles.
87+
You can also enable multiple profiles, e.g. with `docker compose --profile frontend --profile debug up` the profiles `frontend` and `debug` will be enabled.
88+
89+
Profiles can also be set by `COMPOSE_PROFILES` environment variable.
90+
91+
### Set up environment variables
92+
93+
You can set environment variables for various docker-compose options, including the `-f`, `-p` and `--profiles` flags.
94+
95+
Setting the `COMPOSE_FILE` environment variable is equivalent to passing the `-f` flag,
96+
`COMPOSE_PROJECT_NAME` environment variable does the same for to the `-p` flag,
97+
and so does `COMPOSE_PROFILES` environment variable for to the `--profiles` flag.
98+
99+
If flags are explicitly set on command line, associated environment variable is ignored

docs/reference/compose_convert.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
3+
## Description
4+
5+
`docker compose convert` render the actual data model to be applied on target platform. When used with Docker engine,
6+
it merges the Compose files set by `-f` flags, resolves variables in Compose file, and expands short-notation into
7+
fully defined Compose model.
8+
9+
To allow smooth migration from docker-compose, this subcommand declares alias `docker compose config`

docs/reference/compose_down.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
3+
## Description
4+
5+
Stops containers and removes containers, networks, volumes, and images created by ``up`.
6+
7+
By default, the only things removed are:
8+
9+
- Containers for services defined in the Compose file
10+
- Networks defined in the networks section of the Compose file
11+
- The default network, if one is used
12+
13+
Networks and volumes defined as external are never removed.
14+
15+
Anonymous volumes are not removed by default. However, as they don’t have a stable name, they will not be automatically
16+
mounted by a subsequent `up`. For data that needs to persist between updates, use explicit paths as bind mounts or
17+
named volumes.

docs/reference/compose_events.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
## Description
3+
4+
Stream container events for every container in the project.
5+
6+
With the `--json` flag, a json object is printed one per line with the format:
7+
8+
```json
9+
{
10+
"time": "2015-11-20T18:01:03.615550",
11+
"type": "container",
12+
"action": "create",
13+
"id": "213cf7...5fc39a",
14+
"service": "web",
15+
"attributes": {
16+
"name": "application_web_1",
17+
"image": "alpine:edge"
18+
}
19+
}
20+
```
21+
22+
The events that can be received using this can be seen [here](/engine/reference/commandline/events/#object-types).

docs/reference/compose_exec.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
## Description
3+
4+
This is the equivalent of `docker exec` targeting a Compose service.
5+
6+
With this subcommand you can run arbitrary commands in your services. Commands are by default allocating a TTY, so
7+
you can use a command such as `docker compose exec web sh` to get an interactive prompt.

docs/reference/compose_kill.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
## Description
3+
4+
Forces running containers to stop by sending a `SIGKILL` signal. Optionally the signal can be passed, for example:
5+
6+
```
7+
docker-compose kill -s SIGINT
8+
```

docs/reference/compose_logs.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
## Description
3+
4+
Displays log output from services.

docs/reference/compose_ls.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
## Description
3+
4+
List Compose projects running on platform.

docs/reference/compose_pause.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
## Description
3+
4+
Pauses running containers of a service. They can be unpaused with `docker compose unpause`.

docs/reference/compose_ps.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
## Description
3+
4+
Lists containers for a Compose project.

0 commit comments

Comments
 (0)