Add Compose v2 reference (#14716)

* Add compose v2 reference
* Fix broken links
* Remove v1 compose reference files
* Remove Compose CLI completion

Signed-off-by: Usha Mandya <usha.mandya@docker.com>
This commit is contained in:
Usha Mandya 2022-06-21 12:12:05 +01:00 committed by GitHub
parent 1625affcac
commit 9403431ff7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
58 changed files with 141 additions and 771 deletions

View File

@ -911,57 +911,57 @@ reference:
- sectiontitle: Docker Compose CLI reference
section:
- path: /compose/reference/
title: Overview of docker-compose CLI
title: Overview of docker compose CLI
- path: /compose/reference/envvars/
title: CLI environment variables
- path: /compose/reference/build/
title: docker-compose build
title: docker compose build
- path: /compose/reference/config/
title: docker-compose config
title: docker compose config
- path: /compose/reference/create/
title: docker-compose create
title: docker compose create
- path: /compose/reference/down/
title: docker-compose down
title: docker compose down
- path: /compose/reference/events/
title: docker-compose events
title: docker compose events
- path: /compose/reference/exec/
title: docker-compose exec
title: docker compose exec
- path: /compose/reference/help/
title: docker-compose help
title: docker compose help
- path: /compose/reference/images/
title: docker-compose images
title: docker compose images
- path: /compose/reference/kill/
title: docker-compose kill
title: docker compose kill
- path: /compose/reference/logs/
title: docker-compose logs
title: docker compose logs
- path: /compose/reference/pause/
title: docker-compose pause
title: docker compose pause
- path: /compose/reference/port/
title: docker-compose port
title: docker compose port
- path: /compose/reference/ps/
title: docker-compose ps
title: docker compose ps
- path: /compose/reference/pull/
title: docker-compose pull
title: docker compose pull
- path: /compose/reference/push/
title: docker-compose push
title: docker compose push
- path: /compose/reference/restart/
title: docker-compose restart
title: docker compose restart
- path: /compose/reference/rm/
title: docker-compose rm
title: docker compose rm
- path: /compose/reference/run/
title: docker-compose run
title: docker compose run
- path: /compose/reference/scale/
title: docker-compose scale
title: docker compose scale
- path: /compose/reference/start/
title: docker-compose start
title: docker compose start
- path: /compose/reference/stop/
title: docker-compose stop
title: docker compose stop
- path: /compose/reference/top/
title: docker-compose top
title: docker compose top
- path: /compose/reference/unpause/
title: docker-compose unpause
title: docker compose unpause
- path: /compose/reference/up/
title: docker-compose up
title: docker compose up
- title: Daemon CLI (dockerd)
path: /engine/reference/commandline/dockerd/
- sectiontitle: API reference

View File

@ -238,7 +238,7 @@ or combine BuildKits output for the user. For this use case, we have added a
command called [`docker buildx bake`](../engine/reference/commandline/buildx_bake.md).
The `bake` command supports building images from compose files, similar to
[`docker-compose build`](../compose/reference/build.md), but allowing all the
[`docker-compose build`](../engine/reference/commandline/compose_build.md), but allowing all the
services to be built concurrently as part of a single request.
There is also support for custom build rules from HCL/JSON files allowing

View File

@ -1292,7 +1292,7 @@ web:
Specify the default number of containers to deploy for this service. Whenever
you run `docker-compose up`, Compose creates or removes containers to match
the specified number. This value can be overridden using the
[`--scale`](../reference/up.md) flag.
[`--scale`](../../engine/reference/commandline/compose_up.md)
```yaml
web:

View File

@ -2315,7 +2315,7 @@ volumes:
>
> External volumes that do not exist _are created_ if you use [docker stack deploy](#deploy)
> to launch the app in [swarm mode](../../engine/swarm/index.md) (instead of
> [docker compose up](../reference/up.md)). In swarm mode, a volume is
> [docker compose up](../../engine/reference/commandline/compose_up.md)). In swarm mode, a volume is
> automatically created when it is defined by a service. As service tasks are
> scheduled on new nodes, [swarmkit](https://github.com/docker/swarmkit/blob/master/README.md)
> creates the volume on the local node. To learn more, see [moby/moby#29976](https://github.com/moby/moby/issues/29976).

View File

@ -54,13 +54,12 @@ services:
image: "webapp:${TAG}"
```
When you run `docker-compose up`, the `web` service defined above uses the
When you run `docker compose up`, the `web` service defined above uses the
image `webapp:v1.5`. You can verify this with the
[config command](reference/config.md), which prints your resolved application
config to the terminal:
[convert command](../engine/reference/commandline/compose_convert.md), which prints your resolved application config to the terminal:
```console
$ docker-compose config
$ docker compose convert
version: '3'
services:
@ -75,7 +74,7 @@ uses that instead:
```console
$ export TAG=v2.0
$ docker-compose config
$ docker compose convert
version: '3'
services:
@ -92,7 +91,7 @@ appropriately, for example, `.env.ci`, `.env.dev`, `.env.prod`. Passing the file
done using the `--env-file` option:
```console
$ docker-compose --env-file ./config/.env.dev up
$ docker compose --env-file ./config/.env.dev up
```
This file path is relative to the current working directory where the Docker Compose
@ -116,7 +115,7 @@ services:
The `.env` file is loaded by default:
```console
$ docker-compose config
$ docker compose convert
version: '3'
services:
web:
@ -126,7 +125,7 @@ services:
Passing the `--env-file ` argument overrides the default file path:
```console
$ docker-compose --env-file ./config/.env.dev config
$ docker compose --env-file ./config/.env.dev config
version: '3'
services:
web:
@ -136,7 +135,7 @@ services:
When an invalid file path is being passed as `--env-file` argument, Compose returns an error:
```console
$ docker-compose --env-file ./doesnotexist/.env.dev config
$ docker compose --env-file ./doesnotexist/.env.dev config
ERROR: Couldn't find env file: /home/user/./doesnotexist/.env.dev
```
@ -184,19 +183,19 @@ web:
- web-variables.env
```
## Set environment variables with 'docker-compose run'
## Set environment variables with 'docker compose run'
Similar to `docker run -e`, you can set environment variables on a one-off
container with `docker-compose run -e`:
container with `docker compose run -e`:
```console
$ docker-compose run -e DEBUG=1 web python console.py
$ docker compose run -e DEBUG=1 web python console.py
```
You can also pass a variable from the shell by not giving it a value:
```console
$ docker-compose run -e DEBUG web python console.py
$ docker compose run -e DEBUG web python console.py
```
The value of the `DEBUG` variable in the container is taken from the value for
@ -233,7 +232,7 @@ When you run the container, the environment variable defined in the Compose
file takes precedence.
```console
$ docker-compose exec api node
$ docker compose exec api node
> process.env.NODE_ENV
'production'

View File

@ -17,7 +17,7 @@ Yes - see [Controlling startup order](startup-order.md).
## Why do my services take 10 seconds to recreate or stop?
Compose stop attempts to stop a container by sending a `SIGTERM`. It then waits
for a [default timeout of 10 seconds](reference/stop.md). After the timeout,
for a [default timeout of 10 seconds](../engine/reference/commandline/compose_stop.md). After the timeout,
a `SIGKILL` is sent to the container to forcefully kill it. If you
are waiting for this timeout, it means that your containers aren't shutting down
when they receive the `SIGTERM` signal.

View File

@ -1,44 +0,0 @@
---
description: Build or rebuild services.
keywords: fig, composition, compose, docker, orchestration, cli, build
title: docker-compose build
notoc: true
---
```none
Usage: docker-compose build [options] [--build-arg key=val...] [SERVICE...]
Options:
--build-arg key=val Set build-time variables for services.
--compress Compress the build context using gzip.
--force-rm Always remove intermediate containers.
-m, --memory MEM Set memory limit for the build container.
--no-cache Do not use cache when building the image.
--no-rm Do not remove intermediate containers after a successful build.
--parallel Build images in parallel.
--progress string Set type of progress output (`auto`, `plain`, `tty`).
--pull Always attempt to pull a newer version of the image.
-q, --quiet Don't print anything to `STDOUT`.
```
Services are built once and then tagged, by default as `project_service`. For
example, `composetest_db`. If the Compose file specifies an
[image](../compose-file/compose-file-v3.md#image) name, the image is
tagged with that name, substituting any variables beforehand. See
[variable substitution](../compose-file/compose-file-v3.md#variable-substitution).
If you change a service's Dockerfile or the contents of its
build directory, run `docker-compose build` to rebuild it.
## Native build using the docker CLI
Compose by default uses the `docker` CLI to perform builds (also known as "native
build"). By using the `docker` CLI, Compose can take advantage of features such
as [BuildKit](../../develop/develop-images/build_enhancements.md), which are not
supported by Compose itself. BuildKit is enabled by default on Docker Desktop,
but requires the `DOCKER_BUILDKIT=1` environment variable to be set on other
platforms.
Refer to the [Compose CLI environment variables](envvars.md#compose_docker_cli_build)
section to learn how to switch between "native build" and "compose build".

View File

@ -1,25 +0,0 @@
---
description: Config validates and view the compose file.
keywords: fig, composition, compose, docker, orchestration, cli, config
title: docker-compose config
notoc: true
redirect_from:
- /compose/reference/bundle/
---
```none
Usage: docker-compose config [options]
Options:
--resolve-image-digests Pin image tags to digests.
--no-interpolate Don't interpolate environment variables.
-q, --quiet Only validate the configuration, don't print
anything.
--services Print the service names, one per line.
--volumes Print the volume names, one per line.
--hash="*" Print the service config hash, one per line.
Set "service1,service2" for a list of specified services
or use the wildcard symbol to display all services.
```
Validate and view the Compose file.

View File

@ -1,22 +0,0 @@
---
description: Create creates containers for a service.
keywords: fig, composition, compose, docker, orchestration, cli, create
title: docker-compose create
notoc: true
---
> **This command is deprecated.** Use the [up](up.md) command with `--no-start`
instead.
{: .warning }
```none
Usage: docker-compose create [options] [SERVICE...]
Options:
--force-recreate Recreate containers even if their configuration and
image haven't changed. Incompatible with --no-recreate.
--no-recreate If containers already exist, don't recreate them.
Incompatible with --force-recreate.
--no-build Don't build an image, even if it's missing.
--build Build images before creating containers.
```

View File

@ -1,39 +0,0 @@
---
description: docker-compose down
keywords: fig, composition, compose, docker, orchestration, cli, down
title: docker-compose down
notoc: true
---
```none
Usage: docker-compose down [options]
Options:
--rmi type Remove images. Type must be one of:
'all': Remove all images used by any service.
'local': Remove only images that don't have a
custom tag set by the `image` field.
-v, --volumes Remove named volumes declared in the `volumes`
section of the Compose file and anonymous volumes
attached to containers.
--remove-orphans Remove containers for services not defined in the
Compose file
-t, --timeout TIMEOUT Specify a shutdown timeout in seconds.
(default: 10)
```
Stops containers and removes containers, networks, volumes, and images
created by `up`.
By default, the only things removed are:
- Containers for services defined in the Compose file
- Networks defined in the `networks` section of the Compose file
- The default network, if one is used
Networks and volumes defined as `external` are never removed.
Anonymous volumes are not removed by default. However, as they don't
have a stable name, they will not be automatically mounted by a subsequent
`up`. For data that needs to persist between updates, use host or
named volumes.

View File

@ -1,34 +0,0 @@
---
description: Receive real time events from containers.
keywords: fig, composition, compose, docker, orchestration, cli, events
title: docker-compose events
notoc: true
---
```none
Usage: docker-compose events [options] [SERVICE...]
Options:
--json Output events as a stream of json objects
```
Stream container events for every container in the project.
With the `--json` flag, a json object is printed one per line with the
format:
```json
{
"time": "2015-11-20T18:01:03.615550",
"type": "container",
"action": "create",
"id": "213cf7...5fc39a",
"service": "web",
"attributes": {
"name": "application_web_1",
"image": "alpine:edge"
}
}
```
The events that can be received using this can be seen [here](../../engine/reference/commandline/events.md#object-types).

View File

@ -1,26 +0,0 @@
---
description: docker-compose exec
keywords: fig, composition, compose, docker, orchestration, cli, exec
title: docker-compose exec
notoc: true
---
```none
Usage: docker-compose exec [options] [-e KEY=VAL...] SERVICE COMMAND [ARGS...]
Options:
-d, --detach Detached mode: Run command in the background.
--privileged Give extended privileges to the process.
-u, --user USER Run the command as this user.
-T Disable pseudo-tty allocation. By default `docker-compose exec`
allocates a TTY.
--index=index index of the container if there are multiple
instances of a service [default: 1]
-e, --env KEY=VAL Set environment variables (can be used multiple times,
not supported in API < 1.25)
-w, --workdir DIR Path to workdir directory for this command.
```
This is the equivalent of `docker exec`. With this subcommand you can run arbitrary
commands in your services. Commands are by default allocating a TTY, so you can
use a command such as `docker-compose exec web sh` to get an interactive prompt.

View File

@ -1,12 +0,0 @@
---
description: docker-compose help
keywords: fig, composition, compose, docker, orchestration, cli, help
title: docker-compose help
notoc: true
---
```none
Usage: docker-compose help [COMMAND]
```
Displays help and usage instructions for a command.

View File

@ -1,15 +0,0 @@
---
description: Lists images used by the project.
keywords: fig, composition, compose, docker, orchestration, cli, images
title: docker-compose images
notoc: true
---
```none
Usage: docker-compose images [options] [SERVICE...]
Options:
-q, --quiet Only display IDs
```
List images used by the created containers.

View File

@ -1,25 +1,37 @@
---
description: Overview of docker-compose CLI
description: Overview of the Docker Compose CLI
keywords: fig, composition, compose, docker, orchestration, cli, reference, docker-compose
redirect_from:
- /compose/reference/docker-compose/
- /compose/reference/overview/
title: Overview of docker-compose CLI
title: Overview of docker compose CLI
---
This page provides the usage information for the `docker-compose` Command.
This page provides the usage information for the `docker compose` Command.
> Important
>
> The new Compose V2, which supports the `compose` command as part of the Docker
> CLI, is now available.
>
> Compose V2 integrates compose functions into the Docker platform, continuing
> to support most of the previous `docker-compose` features and flags. You can
> run Compose V2 by replacing the hyphen (`-`) with a space, using `docker compose`,
> instead of `docker-compose`.
{: .important}
For more information about Docker Compose V2 GA, see the blog post [Announcing Compose V2 General Availability](https://www.docker.com/blog/announcing-compose-v2-general-availability/){: target="_blank" rel="noopener" class="_"}.
## Command options overview and help
You can also see this information by running `docker-compose --help` from the
You can also see this information by running `docker compose --help` from the
command line.
```none
Define and run multi-container applications with Docker.
Usage:
docker-compose [-f <arg>...] [--profile <name>...] [options] [COMMAND] [ARGS...]
docker-compose -h|--help
docker compose [-f <arg>...] [--profile <name>...] [options] [COMMAND] [ARGS...]
docker compose -h|--help
Options:
-f, --file FILE Specify an alternate compose file
@ -71,10 +83,10 @@ Commands:
top Display the running processes
unpause Unpause services
up Create and start containers
version Show the Docker-Compose version information
version Show the Docker Compose version information
```
You can use Docker Compose binary, `docker-compose [-f <arg>...] [options]
You can use Docker Compose binary, `docker compose [-f <arg>...] [options]
[COMMAND] [ARGS...]`, to build and manage multiple services in Docker containers.
## Use `-f` to specify name and path of one or more Compose files
@ -91,7 +103,7 @@ add to their predecessors.
For example, consider this command line:
```console
$ docker-compose -f docker-compose.yml -f docker-compose.admin.yml run backup_db
$ docker compose -f docker-compose.yml -f docker-compose.admin.yml run backup_db
```
The `docker-compose.yml` file might specify a `webapp` service.
@ -143,14 +155,14 @@ in an environment file.
For an example of using the `-f` option at the command line, suppose you are
running the [Compose Rails sample](../../samples/rails.md), and
have a `docker-compose.yml` file in a directory called `sandbox/rails`. You can
use a command like [docker-compose pull](pull.md) to get the
use a command like [docker compose pull](../../engine/reference/commandline/compose_pull.md) to get the
postgres image for the `db` service from anywhere by using the `-f` flag as
follows: `docker-compose -f ~/sandbox/rails/docker-compose.yml pull db`
follows: `docker compose -f ~/sandbox/rails/docker-compose.yml pull db`
Here's the full example:
```console
$ docker-compose -f ~/sandbox/rails/docker-compose.yml pull db
$ docker compose -f ~/sandbox/rails/docker-compose.yml pull db
Pulling db (postgres:latest)...
latest: Pulling from library/postgres
ef0380f84d05: Pull complete
@ -178,9 +190,9 @@ directory name. See also the [COMPOSE_PROJECT_NAME environment variable](envvars
## Use `--profile` to specify one or more active profiles
Calling `docker-compose --profile frontend up` will start the services with the
Calling `docker compose --profile frontend up` will start the services with the
profile `frontend` and services without specified profiles. You can also enable
multiple profiles, e.g. with `docker-compose --profile frontend --profile debug up`
multiple profiles, e.g. with `docker compose --profile frontend --profile debug up`
the profiles `frontend` and `debug` will be enabled.
See also [_Using profiles with Compose_](../profiles.md) and the
@ -189,7 +201,7 @@ See also [_Using profiles with Compose_](../profiles.md) and the
## Set up environment variables
You can set [environment variables](envvars.md) for various
`docker-compose` options, including the `-f` and `-p` flags.
`docker compose` options, including the `-f` and `-p` flags.
For example, the [COMPOSE_FILE environment variable](envvars.md#compose_file)
relates to the `-f` flag, and `COMPOSE_PROJECT_NAME`

View File

@ -1,19 +0,0 @@
---
description: Forces running containers to stop.
keywords: fig, composition, compose, docker, orchestration, cli, kill
title: docker-compose kill
notoc: true
---
```none
Usage: docker-compose kill [options] [SERVICE...]
Options:
-s SIGNAL SIGNAL to send to the container.
Default signal is SIGKILL.
```
Forces running containers to stop by sending a `SIGKILL` signal. Optionally the
signal can be passed, for example:
docker-compose kill -s SIGINT

View File

@ -1,19 +0,0 @@
---
description: Displays log output from services.
keywords: fig, composition, compose, docker, orchestration, cli, logs
title: docker-compose logs
notoc: true
---
```none
Usage: docker-compose logs [options] [SERVICE...]
Options:
--no-color Produce monochrome output.
-f, --follow Follow log output.
-t, --timestamps Show timestamps.
--tail="all" Number of lines to show from the end of the logs
for each container.
```
Displays log output from services.

View File

@ -1,12 +0,0 @@
---
description: Pauses running containers for a service.
keywords: fig, composition, compose, docker, orchestration, cli, pause
title: docker-compose pause
notoc: true
---
```none
Usage: docker-compose pause [SERVICE...]
```
Pauses running containers of a service. They can be unpaused with `docker-compose unpause`.

View File

@ -1,17 +0,0 @@
---
description: Prints the public port for a port bindings.
keywords: fig, composition, compose, docker, orchestration, cli, port
title: docker-compose port
notoc: true
---
```none
Usage: docker-compose port [options] SERVICE PRIVATE_PORT
Options:
--protocol=proto tcp or udp [default: tcp]
--index=index index of the container if there are multiple
instances of a service [default: 1]
```
Prints the public port for a port binding.

View File

@ -1,26 +0,0 @@
---
description: Lists containers.
keywords: fig, composition, compose, docker, orchestration, cli, ps
title: docker-compose ps
notoc: true
---
```none
Usage: docker-compose ps [options] [SERVICE...]
Options:
-q, --quiet Only display IDs
--services Display services
--filter KEY=VAL Filter services by a property
-a, --all Show all stopped containers (including those created by the run command)
```
Lists containers.
```console
$ docker-compose ps
Name Command State Ports
---------------------------------------------------------------------------------------------
mywordpress_db_1 docker-entrypoint.sh mysqld Up (healthy) 3306/tcp
mywordpress_wordpress_1 /entrypoint.sh apache2-for ... Restarting 0.0.0.0:8000->80/tcp
```

View File

@ -1,60 +0,0 @@
---
description: Pulls service images.
keywords: fig, composition, compose, docker, orchestration, cli, pull
title: docker-compose pull
notoc: true
---
```none
Usage: docker-compose pull [options] [SERVICE...]
Options:
--ignore-pull-failures Pull what it can and ignores images with pull failures.
--parallel Deprecated, pull multiple images in parallel (enabled by default).
--no-parallel Disable parallel pulling.
-q, --quiet Pull without printing progress information
--include-deps Also pull services declared as dependencies
```
Pulls an image associated with a service defined in a `docker-compose.yml` or `docker-stack.yml` file, but does not start containers based on those images.
For example, suppose you have this `docker-compose.yml` file from the [Quickstart: Compose and Rails](../../samples/rails.md) sample.
```yaml
version: '2'
services:
db:
image: postgres
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/myapp
ports:
- "3000:3000"
depends_on:
- db
```
If you run `docker-compose pull ServiceName` in the same directory as the `docker-compose.yml` file that defines the service, Docker pulls the associated image. For example, to call the `postgres` image configured as the `db` service in our example, you would run `docker-compose pull db`.
```console
$ docker-compose pull db
Pulling db (postgres:latest)...
latest: Pulling from library/postgres
cd0a524342ef: Pull complete
9c784d04dcb0: Pull complete
d99dddf7e662: Pull complete
e5bff71e3ce6: Pull complete
cb3e0a865488: Pull complete
31295d654cd5: Pull complete
fc930a4e09f5: Pull complete
8650cce8ef01: Pull complete
61949acd8e52: Pull complete
527a203588c0: Pull complete
26dec14ac775: Pull complete
0efc0ed5a9e5: Pull complete
40cd26695b38: Pull complete
Digest: sha256:fd6c0e2a9d053bebb294bb13765b3e01be7817bf77b01d58c2377ff27a4a46dc
Status: Downloaded newer image for postgres:latest
```

View File

@ -1,35 +0,0 @@
---
description: Pushes service images.
keywords: fig, composition, compose, docker, orchestration, cli, push
title: docker-compose push
notoc: true
---
```none
Usage: docker-compose push [options] [SERVICE...]
Options:
--ignore-push-failures Push what it can and ignores images with push failures.
```
Pushes images for services to their respective `registry/repository`.
The following assumptions are made:
- You are pushing an image you have built locally
- You have access to the build key
## Example
```yaml
version: '3'
services:
service1:
build: .
image: localhost:5000/yourimage # goes to local registry
service2:
build: .
image: your-dockerid/yourimage # goes to your repository on Docker Hub
```

View File

@ -1,26 +0,0 @@
---
description: Restarts Docker Compose services.
keywords: fig, composition, compose, docker, orchestration, cli, restart
title: docker-compose restart
notoc: true
---
```none
Usage: docker-compose restart [options] [SERVICE...]
Options:
-t, --timeout TIMEOUT Specify a shutdown timeout in seconds.
(default: 10)
```
Restarts all stopped and running services.
If you make changes to your `docker-compose.yml` configuration these changes are not reflected after running this command.
For example, changes to environment variables (which are added after a container is built, but before the container's command is executed) are not updated after restarting.
If you are looking to configure a service's restart policy, please refer to
[restart](../compose-file/compose-file-v3.md#restart) in Compose file v3 and
[restart](../compose-file/compose-file-v2.md#restart) in Compose v2. Note that if
you are [deploying a stack in swarm mode](../../engine/reference/commandline/stack_deploy.md),
you should use [restart_policy](../compose-file/compose-file-v3.md#restart_policy), instead.

View File

@ -1,33 +0,0 @@
---
description: Removes stopped service containers.
keywords: fig, composition, compose, docker, orchestration, cli, rm
title: docker-compose rm
notoc: true
---
```none
Usage: docker-compose rm [options] [SERVICE...]
Options:
-f, --force Don't ask to confirm removal
-s, --stop Stop the containers, if required, before removing
-v Remove any anonymous volumes attached to containers
-a, --all Deprecated - no effect.
```
Removes stopped service containers.
By default, anonymous volumes attached to containers are not removed. You
can override this with `-v`. To list all volumes, use `docker volume ls`.
Any data which is not in a volume is lost.
Running the command with no options also removes one-off containers created
by `docker-compose up` or `docker-compose run`:
```none
$ docker-compose rm
Going to remove djangoquickstart_web_run_1
Are you sure? [yN] y
Removing djangoquickstart_web_run_1 ... done
```

View File

@ -1,64 +0,0 @@
---
description: Runs a one-off command on a service.
keywords: fig, composition, compose, docker, orchestration, cli, run
title: docker-compose run
notoc: true
---
```none
Usage:
docker-compose run [options] [-v VOLUME...] [-p PORT...] [-e KEY=VAL...] [-l KEY=VALUE...]
SERVICE [COMMAND] [ARGS...]
Options:
-d, --detach Detached mode: Run container in the background, print
new container name.
--name NAME Assign a name to the container
--entrypoint CMD Override the entrypoint of the image.
-e KEY=VAL Set an environment variable (can be used multiple times)
-l, --label KEY=VAL Add or override a label (can be used multiple times)
-u, --user="" Run as specified username or uid
--no-deps Don't start linked services.
--rm Remove container after run. Ignored in detached mode.
-p, --publish=[] Publish a container's port(s) to the host
--service-ports Run command with the service's ports enabled and mapped
to the host.
--use-aliases Use the service's network aliases in the network(s) the
container connects to.
-v, --volume=[] Bind mount a volume (default [])
-T Disable pseudo-tty allocation. By default `docker-compose run`
allocates a TTY.
-w, --workdir="" Working directory inside the container
```
Runs a one-time command against a service. For example, the following command starts the `web` service and runs `bash` as its command.
docker-compose run web bash
Commands you use with `run` start in new containers with configuration defined by that of the service, including volumes, links, and other details. However, there are two important differences.
First, the command passed by `run` overrides the command defined in the service configuration. For example, if the `web` service configuration is started with `bash`, then `docker-compose run web python app.py` overrides it with `python app.py`.
The second difference is that the `docker-compose run` command does not create any of the ports specified in the service configuration. This prevents port collisions with already-open ports. If you *do want* the service's ports to be created and mapped to the host, specify the `--service-ports` flag:
docker-compose run --service-ports web python manage.py shell
Alternatively, manual port mapping can be specified with the `--publish` or `-p` options, just as when using `docker run`:
docker-compose run --publish 8080:80 -p 2022:22 -p 127.0.0.1:2021:21 web python manage.py shell
If you start a service configured with links, the `run` command first checks to see if the linked service is running and starts the service if it is stopped. Once all the linked services are running, the `run` executes the command you passed it. For example, you could run:
docker-compose run db psql -h db -U docker
This opens an interactive PostgreSQL shell for the linked `db` container.
If you do not want the `run` command to start linked containers, use the `--no-deps` flag:
docker-compose run --no-deps web python manage.py shell
If you want to remove the container after running while overriding the container's restart policy, use the `--rm` flag:
docker-compose run --rm web python manage.py db upgrade
This runs a database upgrade script, and removes the container when finished running, even if a restart policy is specified in the service configuration.

View File

@ -1,32 +0,0 @@
---
description: Sets the number of containers to run for a service.
keywords: fig, composition, compose, docker, orchestration, cli, scale
title: docker-compose scale
notoc: true
---
> **This command is deprecated.** Use the [up](up.md) command with the
`--scale` flag instead. Beware that using `up` with the `--scale` flag has
some [subtle differences](https://github.com/docker/compose/issues/5251) with
the `scale` command, as it incorporates the behaviour of the `up` command.
{: .warning }
```none
Usage: docker-compose scale [options] [SERVICE=NUM...]
Options:
-t, --timeout TIMEOUT Specify a shutdown timeout in seconds.
(default: 10)
```
Sets the number of containers to run for a service.
Numbers are specified as arguments in the form `service=num`. For example:
docker-compose scale web=2 worker=3
>**Tip**: Alternatively, in
[Compose file version 3.x](../compose-file/compose-file-v3.md), you can specify
[replicas](../compose-file/compose-file-v3.md#replicas)
under the [deploy](../compose-file/compose-file-v3.md#deploy) key as part of a
service configuration for [Swarm mode](/engine/swarm/). The `deploy` key and its sub-options (including `replicas`) only works with the `docker stack deploy` command, not `docker-compose up` or `docker-compose run`.

View File

@ -1,12 +0,0 @@
---
description: Starts existing containers for a service.
keywords: fig, composition, compose, docker, orchestration, cli, start
title: docker-compose start
notoc: true
---
```none
Usage: docker-compose start [SERVICE...]
```
Starts existing containers for a service.

View File

@ -1,17 +0,0 @@
---
description: 'Stops running containers without removing them. '
keywords: fig, composition, compose, docker, orchestration, cli, stop
title: docker-compose stop
notoc: true
---
```none
Usage: docker-compose stop [options] [SERVICE...]
Options:
-t, --timeout TIMEOUT Specify a shutdown timeout in seconds.
(default: 10)
```
Stops running containers without removing them. They can be started again with
`docker-compose start`.

View File

@ -1,25 +0,0 @@
---
description: Displays the running processes.
keywords: fig, composition, compose, docker, orchestration, cli, top
title: docker-compose top
notoc: true
---
```none
Usage: docker-compose top [SERVICE...]
```
Displays the running processes.
```console
$ docker-compose top
compose_service_a_1
PID USER TIME COMMAND
----------------------------
4060 root 0:00 top
compose_service_b_1
PID USER TIME COMMAND
----------------------------
4115 root 0:00 top
```

View File

@ -1,12 +0,0 @@
---
description: Unpauses paused containers for a service.
keywords: fig, composition, compose, docker, orchestration, cli, unpause
title: docker-compose unpause
notoc: true
---
```none
Usage: docker-compose unpause [SERVICE...]
```
Unpauses paused containers of a service.

View File

@ -1,63 +0,0 @@
---
description: Builds, (re)creates, starts, and attaches to containers for a service.
keywords: fig, composition, compose, docker, orchestration, cli, up
title: docker-compose up
notoc: true
---
```none
Usage: docker-compose up [options] [--scale SERVICE=NUM...] [SERVICE...]
Options:
-d, --detach Detached mode: Run containers in the background,
print new container names. Incompatible with
--abort-on-container-exit.
--no-color Produce monochrome output.
--quiet-pull Pull without printing progress information
--no-deps Don't start linked services.
--force-recreate Recreate containers even if their configuration
and image haven't changed.
--always-recreate-deps Recreate dependent containers.
Incompatible with --no-recreate.
--no-recreate If containers already exist, don't recreate
them. Incompatible with --force-recreate and
--renew-anon-volumes.
--no-build Don't build an image, even if it's missing.
--no-start Don't start the services after creating them.
--build Build images before starting containers.
--abort-on-container-exit Stops all containers if any container was
stopped. Incompatible with --detach.
--attach-dependencies Attach to dependent containers.
-t, --timeout TIMEOUT Use this timeout in seconds for container
shutdown when attached or when containers are
already running. (default: 10)
-V, --renew-anon-volumes Recreate anonymous volumes instead of retrieving
data from the previous containers.
--remove-orphans Remove containers for services not defined
in the Compose file.
--exit-code-from SERVICE Return the exit code of the selected service
container. Implies --abort-on-container-exit.
--scale SERVICE=NUM Scale SERVICE to NUM instances. Overrides the
`scale` setting in the Compose file if present.
```
Builds, (re)creates, starts, and attaches to containers for a service.
Unless they are already running, this command also starts any linked services.
The `docker-compose up` command aggregates the output of each container (essentially running `docker-compose logs --follow`). When
the command exits, all containers are stopped. Running `docker-compose up --detach`
starts the containers in the background and leaves them running.
If there are existing containers for a service, and the service's configuration
or image was changed after the container's creation, `docker-compose up` picks
up the changes by stopping and recreating the containers (preserving mounted
volumes). To prevent Compose from picking up changes, use the `--no-recreate`
flag.
If you want to force Compose to stop and recreate all containers, use the
`--force-recreate` flag.
If the process encounters an error, the exit code for this command is `1`.
If the process is interrupted using `SIGINT` (`ctrl` + `C`) or `SIGTERM`, the containers are stopped, and the exit code is `0`.
If `SIGINT` or `SIGTERM` is sent again during this shutdown phase, the running containers are killed, and the exit code is `2`.

View File

@ -2,6 +2,9 @@
datafolder: compose-cli
datafile: docker_compose
title: docker compose
redirect_from:
- /compose/reference/docker-compose/
- /compose/reference/help/
---
<!--
Sorry, but the contents of this page are automatically generated from

View File

@ -2,6 +2,8 @@
datafolder: compose-cli
datafile: docker_compose_build
title: docker compose build
redirect_from:
- /compose/reference/build/
---
<!--
Sorry, but the contents of this page are automatically generated from

View File

@ -2,6 +2,8 @@
datafolder: compose-cli
datafile: docker_compose_convert
title: docker compose convert
redirect_from:
- /compose/reference/config/
---
<!--
Sorry, but the contents of this page are automatically generated from

View File

@ -2,6 +2,8 @@
datafolder: compose-cli
datafile: docker_compose_create
title: docker compose create
redirect_from:
- /compose/reference/create/
---
<!--
Sorry, but the contents of this page are automatically generated from

View File

@ -2,6 +2,8 @@
datafolder: compose-cli
datafile: docker_compose_down
title: docker compose down
redirect_from:
- /compose/reference/down/
---
<!--
Sorry, but the contents of this page are automatically generated from

View File

@ -2,6 +2,8 @@
datafolder: compose-cli
datafile: docker_compose_events
title: docker compose events
redirect_from:
- /compose/reference/events
---
<!--
Sorry, but the contents of this page are automatically generated from

View File

@ -2,6 +2,8 @@
datafolder: compose-cli
datafile: docker_compose_exec
title: docker compose exec
redirect_from:
- /compose/reference/exec/
---
<!--
Sorry, but the contents of this page are automatically generated from

View File

@ -2,6 +2,8 @@
datafolder: compose-cli
datafile: docker_compose_images
title: docker compose images
redirect_from:
- /compose/reference/images/
---
<!--
Sorry, but the contents of this page are automatically generated from

View File

@ -2,6 +2,8 @@
datafolder: compose-cli
datafile: docker_compose_kill
title: docker compose kill
redirect_from:
- /compose/reference/kill/
---
<!--
Sorry, but the contents of this page are automatically generated from

View File

@ -2,6 +2,8 @@
datafolder: compose-cli
datafile: docker_compose_logs
title: docker compose logs
redirect_from:
- /compose/reference/logs/
---
<!--
Sorry, but the contents of this page are automatically generated from

View File

@ -2,6 +2,8 @@
datafolder: compose-cli
datafile: docker_compose_pause
title: docker compose pause
redirect_from:
- /compose/reference/pause/
---
<!--
Sorry, but the contents of this page are automatically generated from

View File

@ -2,6 +2,8 @@
datafolder: compose-cli
datafile: docker_compose_port
title: docker compose port
redirect_from:
- /compose/reference/port/
---
<!--
Sorry, but the contents of this page are automatically generated from

View File

@ -2,6 +2,8 @@
datafolder: compose-cli
datafile: docker_compose_ps
title: docker compose ps
redirect_from:
- /compose/reference/ps/
---
<!--
Sorry, but the contents of this page are automatically generated from

View File

@ -2,6 +2,8 @@
datafolder: compose-cli
datafile: docker_compose_pull
title: docker compose pull
redirect_from:
- /compose/reference/pull/
---
<!--
Sorry, but the contents of this page are automatically generated from

View File

@ -2,6 +2,8 @@
datafolder: compose-cli
datafile: docker_compose_push
title: docker compose push
redirect_from:
- /compose/reference/push/
---
<!--
Sorry, but the contents of this page are automatically generated from

View File

@ -2,6 +2,8 @@
datafolder: compose-cli
datafile: docker_compose_restart
title: docker compose restart
redirect_from:
- /compose/reference/restart/
---
<!--
Sorry, but the contents of this page are automatically generated from

View File

@ -2,6 +2,8 @@
datafolder: compose-cli
datafile: docker_compose_rm
title: docker compose rm
redirect_from:
- /compose/reference/rm/
---
<!--
Sorry, but the contents of this page are automatically generated from

View File

@ -2,6 +2,8 @@
datafolder: compose-cli
datafile: docker_compose_run
title: docker compose run
redirect_from:
- /compose/reference/run/
---
<!--
Sorry, but the contents of this page are automatically generated from

View File

@ -2,6 +2,8 @@
datafolder: compose-cli
datafile: docker_compose_start
title: docker compose start
redirect_from:
- /compose/reference/start/
---
<!--
Sorry, but the contents of this page are automatically generated from

View File

@ -2,6 +2,8 @@
datafolder: compose-cli
datafile: docker_compose_stop
title: docker compose stop
redirect_from:
- /compose/reference/stop/
---
<!--
Sorry, but the contents of this page are automatically generated from

View File

@ -2,6 +2,8 @@
datafolder: compose-cli
datafile: docker_compose_top
title: docker compose top
redirect_from:
- /compose/reference/top/
---
<!--
Sorry, but the contents of this page are automatically generated from

View File

@ -2,6 +2,8 @@
datafolder: compose-cli
datafile: docker_compose_unpause
title: docker compose unpause
redirect_from:
- /compose/reference/unpause/
---
<!--
Sorry, but the contents of this page are automatically generated from

View File

@ -2,6 +2,9 @@
datafolder: compose-cli
datafile: docker_compose_up
title: docker compose up
redirect_from:
- /compose/reference/up/
- /compose/reference/scale/
---
<!--
Sorry, but the contents of this page are automatically generated from

View File

@ -2,5 +2,5 @@
title: Docker Compose native build through the CLI
description: Instructions on enabling and disabling Docker Compose native build
keywords: BuildKit, docker-compose build, configuration
redirect_to: /compose/reference/build/#native-build-using-the-docker-cli
redirect_to: /engine/reference/commandline/compose_build/
---

View File

@ -110,7 +110,7 @@ In this step, you create a Django starter project by building the image from the
1. Change to the root of your project directory.
2. Create the Django project by running the [docker-compose run](../compose/reference/run.md)
2. Create the Django project by running the [docker compose run](../engine/reference/commandline/compose_run.md)
command as follows.
```console
@ -199,7 +199,7 @@ In this section, you set up the database connection for Django.
3. Save and close the file.
4. Run the [docker-compose up](../compose/reference/up.md) command from the top level directory for your project.
4. Run the [docker-compose up](../engine/reference/commandline/compose_up.md) command from the top level directory for your project.
```console
$ docker-compose up
@ -267,7 +267,7 @@ In this section, you set up the database connection for Django.
```
* Or, for a more elegant shutdown, switch to a different shell, and run
[docker-compose down](../compose/reference/down.md) from the top level of your
[docker compose down](../engine/reference/commandline/compose_down.md) from the top level of your
Django sample project directory.
```console

View File

@ -100,10 +100,10 @@ services:
### Build the project
With those files in place, you can now generate the Rails skeleton app
using [docker-compose run](../compose/reference/run.md):
using [docker compose run](../engine/reference/commandline/compose_run.md):
```console
$ docker-compose run --no-deps web rails new . --force --database=postgresql
$ docker compose run --no-deps web rails new . --force --database=postgresql
```
First, Compose builds the image for the `web` service using the `Dockerfile`.
@ -154,7 +154,7 @@ changes to the `Gemfile` or the Dockerfile, should be the only times youll ne
to rebuild.)
```console
$ docker-compose build
$ docker compose build
```
### Connect the database
@ -185,11 +185,11 @@ test:
database: myapp_test
```
You can now boot the app with [docker-compose up](../compose/reference/up.md).
You can now boot the app with [docker compose up](../engine/reference/commandline/compose_up.md).
If all is well, you should see some PostgreSQL output:
```console
$ docker-compose up
$ docker compose up
rails_db_1 is up-to-date
Creating rails_web_1 ... done
@ -206,7 +206,7 @@ db_1 | 2018-03-21 20:18:37.772 UTC [1] LOG: database system is ready to accep
Finally, you need to create the database. In another terminal, run:
```console
$ docker-compose run web rake db:create
$ docker compose run web rake db:create
Starting rails_db_1 ... done
Created database 'myapp_development'
Created database 'myapp_test'
@ -223,13 +223,13 @@ browser to see the Rails Welcome.
### Stop the application
To stop the application, run [docker-compose down](../compose/reference/down.md) in
To stop the application, run [docker compose down](../engine/reference/commandline/compose_down.md) in
your project directory. You can use the same terminal window in which you
started the database, or another one where you have access to a command prompt.
This is a clean way to stop the application.
```console
$ docker-compose down
$ docker compose down
Stopping rails_web_1 ... done
Stopping rails_db_1 ... done
@ -242,15 +242,15 @@ Removing network rails_default
### Restart the application
To restart the application run `docker-compose up` in the project directory.
To restart the application run `docker compose up` in the project directory.
### Rebuild the application
If you make changes to the Gemfile or the Compose file to try out some different
configurations, you need to rebuild. Some changes require only
`docker-compose up --build`, but a full rebuild requires a re-run of
`docker-compose run web bundle install` to sync changes in the `Gemfile.lock` to
the host, followed by `docker-compose up --build`.
`docker compose up --build`, but a full rebuild requires a re-run of
`docker compose run web bundle install` to sync changes in the `Gemfile.lock` to
the host, followed by `docker compose up --build`.
Here is an example of the first case, where a full rebuild is not necessary.
Suppose you simply want to change the exposed port on the local host from `3000`
@ -263,7 +263,7 @@ ports:
- "3001:3000"
```
Now, rebuild and restart the app with `docker-compose up --build`.
Now, rebuild and restart the app with `docker compose up --build`.
Inside the container, your app is running on the same port as before `3000`, but
the Rails Welcome is now available on `http://localhost:3001` on your local
@ -274,6 +274,6 @@ host.
- [Docker Compose overview](../compose/index.md)
- [Install Docker Compose](../compose/install/index.md)
- [Getting Started with Docker Compose](../compose/gettingstarted.md)
- [Docker Compose Command line reference](../compose/reference/index.md)
- [Docker Compose Command line reference](../engine/reference/commandline/compose.md)
- [Compose file reference](../compose/compose-file/index.md)
- [Awesome Compose samples](https://github.com/docker/awesome-compose/){:target="_blank" rel="noopener" class="_"}

View File

@ -81,14 +81,14 @@ Compose to set up and run WordPress. Before starting, make sure you have
### Build the project
Now, run `docker-compose up -d` from your project directory.
Now, run `docker compose up -d` from your project directory.
This runs [`docker-compose up`](../compose/reference/up.md) in detached mode, pulls
This runs [`docker compose up`](../engine/reference/commandline/compose_up.md) in detached mode, pulls
the needed Docker images, and starts the wordpress and database containers, as shown in
the example below.
```console
$ docker-compose up -d
$ docker compose up -d
Creating network "my_wordpress_default" with the default driver
Pulling db (mysql:5.7)...
@ -135,10 +135,10 @@ browser.
### Shutdown and cleanup
The command [`docker-compose down`](../compose/reference/down.md) removes the
The command [`docker compose down`](../engine/reference/commandline/compose_down.md) removes the
containers and default network, but preserves your WordPress database.
The command `docker-compose down --volumes` removes the containers, default
The command `docker compose down --volumes` removes the containers, default
network, and the WordPress database.
## More Compose documentation