Replacing v1 syntax (#15185)

* Replacing v1 syntax
This commit is contained in:
Dora Ribeiro 2022-07-26 18:08:28 +01:00 committed by GitHub
parent 15e4c88517
commit 72a3a45c0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 49 additions and 48 deletions

View File

@ -6,15 +6,14 @@ title: Compose command compatibility with docker-compose
The `compose` command in the Docker CLI supports most of the `docker-compose` commands and flags. It is expected to be a drop-in replacement for `docker-compose`. The `compose` command in the Docker CLI supports most of the `docker-compose` commands and flags. It is expected to be a drop-in replacement for `docker-compose`.
If you see any Compose functionality that is not available in the `compose` command, create an issue in the [Compose](https://github.com/docker/compose/issues){:target="_blank" rel="noopener" If you see any Compose functionality that is not available in the `compose` command, create an issue in the [Compose](https://github.com/docker/compose/issues){:target="_blank" rel="noopener" class="_"} GitHub repository, so we can prioritize it.
class="_"} GitHub repository, so we can prioritize it.
## Commands or flags not yet implemented ## Commands or flags not yet implemented
The following commands have not been implemented yet, and may be implemented at a later time. The following commands have not been implemented yet, and may be implemented at a later time.
Let us know if these commands are a higher priority for your use cases. Let us know if these commands are a higher priority for your use cases.
`compose build --memory`: This option is not yet supported by buildkit. The flag is currently supported, but is hidden to avoid breaking existing Compose usage. It does not have any effect. `compose build --memory`: This option is not yet supported by BuildKit. The flag is currently supported, but is hidden to avoid breaking existing Compose usage. It does not have any effect.
## Flags that will not be implemented ## Flags that will not be implemented

View File

@ -31,7 +31,7 @@ the rules described in
To use multiple override files, or an override file with a different name, you To use multiple override files, or an override file with a different name, you
can use the `-f` option to specify the list of files. Compose merges files in can use the `-f` option to specify the list of files. Compose merges files in
the order they're specified on the command line. See the the order they're specified on the command line. See the
[`docker-compose` command reference](reference/index.md) for more information [`docker compose` command reference](reference/index.md) for more information
about using `-f`. about using `-f`.
When you use multiple configuration files, you must make sure all paths in the When you use multiple configuration files, you must make sure all paths in the
@ -99,7 +99,7 @@ cache:
- 6379:6379 - 6379:6379
``` ```
When you run `docker-compose up` it reads the overrides automatically. When you run `docker compose up` it reads the overrides automatically.
Now, it would be nice to use this Compose app in a production environment. So, Now, it would be nice to use this Compose app in a production environment. So,
create another override file (which might be stored in a different git create another override file (which might be stored in a different git
@ -122,7 +122,7 @@ cache:
To deploy with this production Compose file you can run To deploy with this production Compose file you can run
```console ```console
$ docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d $ docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d
``` ```
This deploys all three services using the configuration in This deploys all three services using the configuration in
@ -135,7 +135,7 @@ production.
#### Administrative tasks #### Administrative tasks
Another common use case is running adhoc or administrative tasks against one Another common use case is running when necessary or administrative tasks against one
or more services in a Compose app. This example demonstrates running a or more services in a Compose app. This example demonstrates running a
database backup. database backup.
@ -161,11 +161,11 @@ export or backup.
- db - db
``` ```
To start a normal environment run `docker-compose up -d`. To run a database To start a normal environment run `docker compose up -d`. To run a database
backup, include the `docker-compose.admin.yml` as well. backup, include the `docker-compose.admin.yml` as well.
```console ```console
$ docker-compose -f docker-compose.yml -f docker-compose.admin.yml \ $ docker compose -f docker-compose.yml -f docker-compose.admin.yml \
run dbadmin db-backup run dbadmin db-backup
``` ```

View File

@ -63,13 +63,13 @@ or the [`COMPOSE_PROJECT_NAME` environment variable](reference/envvars.md#compos
## What's the difference between `up`, `run`, and `start`? ## What's the difference between `up`, `run`, and `start`?
Typically, you want `docker-compose up`. Use `up` to start or restart all the Typically, you want `docker compose up`. Use `up` to start or restart all the
services defined in a `docker-compose.yml`. In the default "attached" services defined in a `docker-compose.yml`. In the default "attached"
mode, you see all the logs from all the containers. In "detached" mode (`-d`), mode, you see all the logs from all the containers. In "detached" mode (`-d`),
Compose exits after starting the containers, but the containers continue to run Compose exits after starting the containers, but the containers continue to run
in the background. in the background.
The `docker-compose run` command is for running "one-off" or "adhoc" tasks. It The `docker compose run` command is for running "one-off" or "adhoc" tasks. It
requires the service name you want to run and only starts containers for services requires the service name you want to run and only starts containers for services
that the running service depends on. Use `run` to run tests or perform that the running service depends on. Use `run` to run tests or perform
an administrative task such as removing or adding data to a data volume an administrative task such as removing or adding data to a data volume
@ -77,18 +77,18 @@ container. The `run` command acts like `docker run -ti` in that it opens an
interactive terminal to the container and returns an exit status matching the interactive terminal to the container and returns an exit status matching the
exit status of the process in the container. exit status of the process in the container.
The `docker-compose start` command is useful only to restart containers The `docker compose start` command is useful only to restart containers
that were previously created, but were stopped. It never creates new that were previously created, but were stopped. It never creates new
containers. containers.
## Can I use json instead of yaml for my Compose file? ## Can I use JSON instead of YAML for my Compose file?
Yes. [Yaml is a superset of json](https://stackoverflow.com/a/1729545/444646) so Yes. [YAML is a superset of JSON](https://stackoverflow.com/a/1729545/444646) so
any JSON file should be valid Yaml. To use a JSON file with Compose, any JSON file should be valid YAML. To use a JSON file with Compose,
specify the filename to use, for example: specify the filename to use, for example:
```console ```console
$ docker-compose -f docker-compose.json up $ docker compose -f docker-compose.json up
``` ```
## Should I include my code with `COPY`/`ADD` or a volume? ## Should I include my code with `COPY`/`ADD` or a volume?

View File

@ -6,7 +6,9 @@ title: Enabling GPU access with Compose
Compose services can define GPU device reservations if the Docker host contains such devices and the Docker Daemon is set accordingly. For this, make sure to install the [prerequisites](../config/containers/resource_constraints.md#gpu) if you have not already done so. Compose services can define GPU device reservations if the Docker host contains such devices and the Docker Daemon is set accordingly. For this, make sure to install the [prerequisites](../config/containers/resource_constraints.md#gpu) if you have not already done so.
The examples in the following sections focus specifically on providing service containers access to GPU devices with Docker Compose. You can use either `docker-compose` or `docker compose` commands. The examples in the following sections focus specifically on providing service containers access to GPU devices with Docker Compose.
You can use either `docker-compose` or `docker compose` commands.
See also, [Compose command compatibility with docker-compose](cli-command-compatibility.md).
### Use of service `runtime` property from Compose v2.3 format (legacy) ### Use of service `runtime` property from Compose v2.3 format (legacy)
@ -60,7 +62,7 @@ services:
Run with Docker Compose: Run with Docker Compose:
```console ```console
$ docker-compose up $ docker compose up
Creating network "gpu_default" with the default driver Creating network "gpu_default" with the default driver
Creating gpu_test_1 ... done Creating gpu_test_1 ... done
Attaching to gpu_test_1 Attaching to gpu_test_1
@ -102,7 +104,7 @@ services:
``` ```
```console ```console
$ docker-compose up $ docker compose up
Creating network "gpu_default" with the default driver Creating network "gpu_default" with the default driver
Creating gpu_test_1 ... done Creating gpu_test_1 ... done
Attaching to gpu_test_1 Attaching to gpu_test_1
@ -161,7 +163,7 @@ services:
``` ```
```sh ```sh
$ docker-compose up $ docker compose up
... ...
Created TensorFlow device (/device:GPU:0 with 13970 MB memory -> physical GPU (device: 0, name: Tesla T4, pci bus id: 0000:00:1b.0, compute capability: 7.5) Created TensorFlow device (/device:GPU:0 with 13970 MB memory -> physical GPU (device: 0, name: Tesla T4, pci bus id: 0000:00:1b.0, compute capability: 7.5)
... ...

View File

@ -29,7 +29,7 @@ anywhere.
2. Define the services that make up your app in `docker-compose.yml` 2. Define the services that make up your app in `docker-compose.yml`
so they can be run together in an isolated environment. so they can be run together in an isolated environment.
3. Run `docker compose up` and the [Docker compose command](#compose-v2-and-the-new-docker-compose-command) starts and runs your entire app. You can alternatively run `docker-compose up` using the docker-compose binary. 3. Run `docker compose up` and the [Docker compose command](#compose-v2-and-the-new-docker-compose-command) starts and runs your entire app. You can alternatively run `docker-compose up` using Compose standalone(`docker-compose` binary).
A `docker-compose.yml` looks like this: A `docker-compose.yml` looks like this:
@ -132,7 +132,7 @@ for it can be defined with the `--project-directory` command line option.
### Preserve volume data when containers are created ### Preserve volume data when containers are created
Compose preserves all volumes used by your services. When `docker-compose up` Compose preserves all volumes used by your services. When `docker compose up`
runs, if it finds any containers from previous runs, it copies the volumes from runs, if it finds any containers from previous runs, it copies the volumes from
the old container to the new container. This process ensures that any data the old container to the new container. This process ensures that any data
you've created in volumes isn't lost. you've created in volumes isn't lost.
@ -190,9 +190,9 @@ environment in which to run tests. Compose provides a convenient way to create
and destroy isolated testing environments for your test suite. By defining the full environment in a [Compose file](compose-file/index.md), you can create and destroy these environments in just a few commands: and destroy isolated testing environments for your test suite. By defining the full environment in a [Compose file](compose-file/index.md), you can create and destroy these environments in just a few commands:
```console ```console
$ docker-compose up -d $ docker compose up -d
$ ./run_tests $ ./run_tests
$ docker-compose down $ docker compose down
``` ```
### Single host deployments ### Single host deployments

View File

@ -34,7 +34,7 @@ services:
- "8001:5432" - "8001:5432"
``` ```
When you run `docker-compose up`, the following happens: When you run `docker compose up`, the following happens:
1. A network called `myapp_default` is created. 1. A network called `myapp_default` is created.
2. A container is created using `web`'s configuration. It joins the network 2. A container is created using `web`'s configuration. It joins the network
@ -68,7 +68,7 @@ look like `postgres://{DOCKER_IP}:8001`.
## Update containers ## Update containers
If you make a configuration change to a service and run `docker-compose up` to update it, the old container is removed and the new one joins the network under a different IP address but the same name. Running containers can look up that name and connect to the new address, but the old address stops working. If you make a configuration change to a service and run `docker compose up` to update it, the old container is removed and the new one joins the network under a different IP address but the same name. Running containers can look up that name and connect to the new address, but the old address stops working.
If any containers have connections open to the old container, they are closed. It is a container's responsibility to detect this condition, look up the name again and reconnect. If any containers have connections open to the old container, they are closed. It is a container's responsibility to detect this condition, look up the name again and reconnect.

View File

@ -35,7 +35,7 @@ Once you've got a second configuration file, tell Compose to use it with the
`-f` option: `-f` option:
```console ```console
$ docker-compose -f docker-compose.yml -f production.yml up -d $ docker compose -f docker-compose.yml -f production.yml up -d
``` ```
See [Using multiple compose files](extends.md#different-environments) for a more See [Using multiple compose files](extends.md#different-environments) for a more
@ -48,8 +48,8 @@ recreate your app's containers. To redeploy a service called
`web`, use: `web`, use:
```console ```console
$ docker-compose build web $ docker compose build web
$ docker-compose up --no-deps -d web $ docker compose up --no-deps -d web
``` ```
This first rebuilds the image for `web` and then stop, destroy, and recreate This first rebuilds the image for `web` and then stop, destroy, and recreate
@ -60,9 +60,9 @@ recreating any services which `web` depends on.
You can use Compose to deploy an app to a remote Docker host by setting the You can use Compose to deploy an app to a remote Docker host by setting the
`DOCKER_HOST`, `DOCKER_TLS_VERIFY`, and `DOCKER_CERT_PATH` environment variables `DOCKER_HOST`, `DOCKER_TLS_VERIFY`, and `DOCKER_CERT_PATH` environment variables
appropriately. appropriately. See also [Compose CLI environment variables](../compose/reference/envvars.md).
Once you've set up your environment variables, all the normal `docker-compose` Once you've set up your environment variables, all the normal `docker compose`
commands work with no further configuration. commands work with no further configuration.
## Compose documentation ## Compose documentation

View File

@ -46,7 +46,7 @@ Here the services `frontend` and `phpmyadmin` are assigned to the profiles
respective profiles are enabled. respective profiles are enabled.
Services without a `profiles` attribute will _always_ be enabled, i.e. in this Services without a `profiles` attribute will _always_ be enabled, i.e. in this
case running `docker-compose up` would only start `backend` and `db`. case running `docker compose up` would only start `backend` and `db`.
Valid profile names follow the regex format of `[a-zA-Z0-9][a-zA-Z0-9_.-]+`. Valid profile names follow the regex format of `[a-zA-Z0-9][a-zA-Z0-9_.-]+`.
@ -61,8 +61,8 @@ To enable a profile supply the `--profile` [command-line option](reference/index
use the [`COMPOSE_PROFILES` environment variable](reference/envvars.md#compose_profiles): use the [`COMPOSE_PROFILES` environment variable](reference/envvars.md#compose_profiles):
```sh ```sh
$ docker-compose --profile debug up $ docker compose --profile debug up
$ COMPOSE_PROFILES=debug docker-compose up $ COMPOSE_PROFILES=debug docker compose up
``` ```
The above command would both start your application with the `debug` profile enabled. The above command would both start your application with the `debug` profile enabled.
@ -73,8 +73,8 @@ Multiple profiles can be specified by passing multiple `--profile` flags or
a comma-separated list for the `COMPOSE_PROFILES` environment variable: a comma-separated list for the `COMPOSE_PROFILES` environment variable:
```sh ```sh
$ docker-compose --profile frontend --profile debug up $ docker compose --profile frontend --profile debug up
$ COMPOSE_PROFILES=frontend,debug docker-compose up $ COMPOSE_PROFILES=frontend,debug docker compose up
``` ```
## Auto-enabling profiles and dependency resolution ## Auto-enabling profiles and dependency resolution
@ -104,14 +104,14 @@ services:
```sh ```sh
# will only start backend and db # will only start backend and db
$ docker-compose up -d $ docker compose up -d
# this will run db-migrations (and - if necessary - start db) # this will run db-migrations (and - if necessary - start db)
# by implicitly enabling profile `tools` # by implicitly enabling profile `tools`
$ docker-compose run db-migrations $ docker compose run db-migrations
``` ```
But keep in mind that `docker-compose` will only automatically enable the But keep in mind that `docker compose` will only automatically enable the
profiles of the services on the command line and not of any dependencies. This profiles of the services on the command line and not of any dependencies. This
means that all services the targeted service `depends_on` must have a common means that all services the targeted service `depends_on` must have a common
profile with it, be always enabled (by omitting `profiles`) or have a matching profile with it, be always enabled (by omitting `profiles`) or have a matching
@ -142,14 +142,14 @@ services:
```sh ```sh
# will only start "web" # will only start "web"
$ docker-compose up -d $ docker compose up -d
# this will start mock-backend (and - if necessary - db) # this will start mock-backend (and - if necessary - db)
# by implicitly enabling profile `dev` # by implicitly enabling profile `dev`
$ docker-compose up -d mock-backend $ docker compose up -d mock-backend
# this will fail because profile "dev" is disabled # this will fail because profile "dev" is disabled
$ docker-compose up phpmyadmin $ docker compose up phpmyadmin
``` ```
Although targeting `phpmyadmin` will automatically enable its profiles - i.e. Although targeting `phpmyadmin` will automatically enable its profiles - i.e.
@ -166,8 +166,8 @@ or enable a profile of `db` explicitly:
```sh ```sh
# profile "debug" is enabled automatically by targeting phpmyadmin # profile "debug" is enabled automatically by targeting phpmyadmin
$ docker-compose --profile dev up phpmyadmin $ docker compose --profile dev up phpmyadmin
$ COMPOSE_PROFILES=dev docker-compose up phpmyadmin $ COMPOSE_PROFILES=dev docker compose up phpmyadmin
``` ```

View File

@ -26,7 +26,7 @@ redirect_from:
- Fixed parsing of properties `deploy.limits.cpus` and `deploy.limits.pids` to respect floating-point values. Fixes [#9542](https://github.com/docker/compose/issues/9542){:target="_blank" rel="noopener" class="_"} and [#9501](https://github.com/docker/compose/issues/9501){:target="_blank" rel="noopener" class="_"}. - Fixed parsing of properties `deploy.limits.cpus` and `deploy.limits.pids` to respect floating-point values. Fixes [#9542](https://github.com/docker/compose/issues/9542){:target="_blank" rel="noopener" class="_"} and [#9501](https://github.com/docker/compose/issues/9501){:target="_blank" rel="noopener" class="_"}.
- Fixed `compose ps` output to list all exposed ports. Fixes [#9257](https://github.com/docker/compose/issues/9527){:target="_blank" rel="noopener" class="_"}. - Fixed `compose ps` output to list all exposed ports. Fixes [#9257](https://github.com/docker/compose/issues/9527){:target="_blank" rel="noopener" class="_"}.
- Fixed spelling mistakes in `compose ps` code. - Fixed spelling mistakes in `compose ps` code.
- Fixed `docker-compose`to honor `--no-ansi` even when deprecated option is requested. - Fixed `docker compose` to honor `--no-ansi` even when deprecated option is requested.
- Fixed network name and network ID possible ambiguity. - Fixed network name and network ID possible ambiguity.
@ -113,7 +113,7 @@ For the full change log or additional information, check the [Compose repository
- Fixed panic with `compose down` command when `-p` flag specified. Fixes [#9353](https://github.com/docker/compose/issues/9353){:target="_blank" rel="noopener" class="_"}. - Fixed panic with `compose down` command when `-p` flag specified. Fixes [#9353](https://github.com/docker/compose/issues/9353){:target="_blank" rel="noopener" class="_"}.
- Passed newly created project as input to start services (`docker compose up`). Fixes [#9356](https://github.com/docker/compose/issues/9356){:target="_blank" rel="noopener" class="_"}. - Passed newly created project as input to start services (`docker compose up`). Fixes [#9356](https://github.com/docker/compose/issues/9356){:target="_blank" rel="noopener" class="_"}.
- Included services declared under links in docker-compose file as implicit dependencies. Fixes [#9301](https://github.com/docker/compose/issues/9301){:target="_blank" rel="noopener" class="_"}. - Included services declared under links in docker-compose file as implicit dependencies. Fixes [#9301](https://github.com/docker/compose/issues/9301){:target="_blank" rel="noopener" class="_"}.
- Added changes `docker-compose pull` command to respect defined policy: 1) skip services configured as `pull_policy: never` and 2) ignore those with an existing image and `pull_policy: missing`. Fixes [#3660](https://github.com/docker/compose/issues/3660){:target="_blank" rel="noopener" class="_"}. - Added changes `docker compose pull` command to respect defined policy: 1) skip services configured as `pull_policy: never` and 2) ignore those with an existing image and `pull_policy: missing`. Fixes [#3660](https://github.com/docker/compose/issues/3660){:target="_blank" rel="noopener" class="_"}.
- Error building project from resources is no longer ignored in order to prevent `down` panic. Fixes [#9383](https://github.com/docker/compose/issues/9383){:target="_blank" rel="noopener" class="_"}. - Error building project from resources is no longer ignored in order to prevent `down` panic. Fixes [#9383](https://github.com/docker/compose/issues/9383){:target="_blank" rel="noopener" class="_"}.
- Enforced project name to be lowercase. Fixes [#9378](https://github.com/docker/compose/issues/9378){:target="_blank" rel="noopener" class="_"}. - Enforced project name to be lowercase. Fixes [#9378](https://github.com/docker/compose/issues/9378){:target="_blank" rel="noopener" class="_"}.
- Added support to build-time secrets. Fixes [#6358](https://github.com/docker/compose/issues/6358){:target="_blank" rel="noopener" class="_"}. - Added support to build-time secrets. Fixes [#6358](https://github.com/docker/compose/issues/6358){:target="_blank" rel="noopener" class="_"}.
@ -185,7 +185,7 @@ For the full change log or additional information, check the [Compose repository
- Dependencies update: Bumped github.com/spf13/cobra from 1.3.0 to 1.4.0. Cobra library no longer requires Viper and all of its indirect dependencies [See cobra's release page](https://github.com/spf13/cobra/releases){:target="_blank" rel="noopener" class="_"}. - Dependencies update: Bumped github.com/spf13/cobra from 1.3.0 to 1.4.0. Cobra library no longer requires Viper and all of its indirect dependencies [See cobra's release page](https://github.com/spf13/cobra/releases){:target="_blank" rel="noopener" class="_"}.
- Dependencies update: Bumped buildx from v0.7.1 to v0.8.0. - Dependencies update: Bumped buildx from v0.7.1 to v0.8.0.
- Removed the need to get the original compose.yaml file to run 'docker compose kill'. - Removed the need to get the original compose.yaml file to run 'docker compose kill'.
- `docker-compose down -v` now does not remove external volumes and networks as per the option's expected and documented behavior. Whenever project is specified it is also now used to enforce down to only remove resources listed in compose.yaml file. - `docker compose down -v` now does not remove external volumes and networks as per the option's expected and documented behavior. Whenever project is specified it is also now used to enforce down to only remove resources listed in compose.yaml file.
Fixes [#9172](https://github.com/docker/compose/issues/9172){:target="_blank" rel="noopener" class="_"}, [#9145](https://github.com/docker/compose/issues/9145){:target="_blank" rel="noopener" class="_"}. Fixes [#9172](https://github.com/docker/compose/issues/9172){:target="_blank" rel="noopener" class="_"}, [#9145](https://github.com/docker/compose/issues/9145){:target="_blank" rel="noopener" class="_"}.
- Introduced changes to use RunExec and RunStart from docker/cli to handle all the interactive/tty/* terminal logic. - Introduced changes to use RunExec and RunStart from docker/cli to handle all the interactive/tty/* terminal logic.
- Changed Compose API reference docs automation to pick up diffs code vs. docs. - Changed Compose API reference docs automation to pick up diffs code vs. docs.
@ -203,7 +203,7 @@ For the releases later than 1.29.2 and earlier than 2.3.4, please check the [Com
### Miscellaneous ### Miscellaneous
- Removed the prompt to use `docker compose` in the `up` command. - Removed the prompt to use `docker-compose` in the `up` command.
- Bumped `py` to `1.10.0` in `requirements-indirect.txt`. - Bumped `py` to `1.10.0` in `requirements-indirect.txt`.