2021-03-08 15:47:24 +01:00
|
|
|
|
command: docker compose run
|
|
|
|
|
short: Run a one-off command on a service.
|
2021-09-13 17:41:21 +02:00
|
|
|
|
long: |-
|
2022-07-26 14:58:08 +02:00
|
|
|
|
Runs a one-time command against a service.
|
2021-09-13 17:41:21 +02:00
|
|
|
|
|
2022-07-26 14:58:08 +02:00
|
|
|
|
the following command starts the `web` service and runs `bash` as its command:
|
2021-09-13 17:41:21 +02:00
|
|
|
|
|
2022-07-26 14:58:08 +02:00
|
|
|
|
```console
|
|
|
|
|
$ docker compose run web bash
|
|
|
|
|
```
|
2021-09-13 17:41:21 +02:00
|
|
|
|
|
2022-07-26 14:58:08 +02:00
|
|
|
|
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:
|
2021-09-13 17:41:21 +02:00
|
|
|
|
|
2022-07-26 14:58:08 +02:00
|
|
|
|
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`.
|
2021-09-13 17:41:21 +02:00
|
|
|
|
|
2022-07-26 14:58:08 +02:00
|
|
|
|
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`
|
2021-09-13 17:41:21 +02:00
|
|
|
|
|
2022-07-26 14:58:08 +02:00
|
|
|
|
```console
|
|
|
|
|
$ docker compose run --service-ports web python manage.py shell
|
|
|
|
|
```
|
2021-09-13 17:41:21 +02:00
|
|
|
|
|
2022-07-26 14:58:08 +02:00
|
|
|
|
Alternatively, manual port mapping can be specified with the `--publish` or `-p` options, just as when using docker run:
|
2021-09-13 17:41:21 +02:00
|
|
|
|
|
2022-07-26 14:58:08 +02:00
|
|
|
|
```console
|
|
|
|
|
$ docker compose run --publish 8080:80 -p 2022:22 -p 127.0.0.1:2021:21 web python manage.py shell
|
|
|
|
|
```
|
2021-09-13 17:41:21 +02:00
|
|
|
|
|
2022-07-26 14:58:08 +02:00
|
|
|
|
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:
|
2021-09-13 17:41:21 +02:00
|
|
|
|
|
2022-07-26 14:58:08 +02:00
|
|
|
|
```console
|
|
|
|
|
$ docker compose run db psql -h db -U docker
|
|
|
|
|
```
|
2021-09-13 17:41:21 +02:00
|
|
|
|
|
2022-07-26 14:58:08 +02:00
|
|
|
|
This opens an interactive PostgreSQL shell for the linked `db` container.
|
2021-09-13 17:41:21 +02:00
|
|
|
|
|
2022-07-26 14:58:08 +02:00
|
|
|
|
If you do not want the run command to start linked containers, use the `--no-deps` flag:
|
2021-09-13 17:41:21 +02:00
|
|
|
|
|
2022-07-26 14:58:08 +02:00
|
|
|
|
```console
|
|
|
|
|
$ docker compose run --no-deps web python manage.py shell
|
|
|
|
|
```
|
2021-09-13 17:41:21 +02:00
|
|
|
|
|
2022-07-26 14:58:08 +02:00
|
|
|
|
If you want to remove the container after running while overriding the container’s restart policy, use the `--rm` flag:
|
2021-09-13 17:41:21 +02:00
|
|
|
|
|
2022-07-26 14:58:08 +02:00
|
|
|
|
```console
|
|
|
|
|
$ docker compose run --rm web python manage.py db upgrade
|
|
|
|
|
```
|
2021-09-13 17:41:21 +02:00
|
|
|
|
|
2022-07-26 14:58:08 +02:00
|
|
|
|
This runs a database upgrade script, and removes the container when finished running, even if a restart policy is
|
|
|
|
|
specified in the service configuration.
|
2022-08-02 13:11:57 +02:00
|
|
|
|
usage: docker compose run [OPTIONS] SERVICE [COMMAND] [ARGS...]
|
2021-03-08 15:47:24 +01:00
|
|
|
|
pname: docker compose
|
|
|
|
|
plink: docker_compose.yaml
|
|
|
|
|
options:
|
2022-11-17 12:29:19 +01:00
|
|
|
|
- option: build
|
|
|
|
|
value_type: bool
|
|
|
|
|
default_value: "false"
|
|
|
|
|
description: Build image before starting container.
|
|
|
|
|
deprecated: false
|
|
|
|
|
hidden: false
|
|
|
|
|
experimental: false
|
|
|
|
|
experimentalcli: false
|
|
|
|
|
kubernetes: false
|
|
|
|
|
swarm: false
|
2022-07-26 14:58:08 +02:00
|
|
|
|
- option: detach
|
|
|
|
|
shorthand: d
|
|
|
|
|
value_type: bool
|
|
|
|
|
default_value: "false"
|
|
|
|
|
description: Run container in background and print container ID
|
|
|
|
|
deprecated: false
|
|
|
|
|
hidden: false
|
|
|
|
|
experimental: false
|
|
|
|
|
experimentalcli: false
|
|
|
|
|
kubernetes: false
|
|
|
|
|
swarm: false
|
|
|
|
|
- option: entrypoint
|
|
|
|
|
value_type: string
|
|
|
|
|
description: Override the entrypoint of the image
|
|
|
|
|
deprecated: false
|
|
|
|
|
hidden: false
|
|
|
|
|
experimental: false
|
|
|
|
|
experimentalcli: false
|
|
|
|
|
kubernetes: false
|
|
|
|
|
swarm: false
|
|
|
|
|
- option: env
|
|
|
|
|
shorthand: e
|
|
|
|
|
value_type: stringArray
|
|
|
|
|
default_value: '[]'
|
|
|
|
|
description: Set environment variables
|
|
|
|
|
deprecated: false
|
|
|
|
|
hidden: false
|
|
|
|
|
experimental: false
|
|
|
|
|
experimentalcli: false
|
|
|
|
|
kubernetes: false
|
|
|
|
|
swarm: false
|
|
|
|
|
- option: interactive
|
|
|
|
|
shorthand: i
|
|
|
|
|
value_type: bool
|
|
|
|
|
default_value: "true"
|
|
|
|
|
description: Keep STDIN open even if not attached.
|
|
|
|
|
deprecated: false
|
|
|
|
|
hidden: false
|
|
|
|
|
experimental: false
|
|
|
|
|
experimentalcli: false
|
|
|
|
|
kubernetes: false
|
|
|
|
|
swarm: false
|
|
|
|
|
- option: label
|
|
|
|
|
shorthand: l
|
|
|
|
|
value_type: stringArray
|
|
|
|
|
default_value: '[]'
|
|
|
|
|
description: Add or override a label
|
|
|
|
|
deprecated: false
|
|
|
|
|
hidden: false
|
|
|
|
|
experimental: false
|
|
|
|
|
experimentalcli: false
|
|
|
|
|
kubernetes: false
|
|
|
|
|
swarm: false
|
|
|
|
|
- option: name
|
|
|
|
|
value_type: string
|
|
|
|
|
description: Assign a name to the container
|
|
|
|
|
deprecated: false
|
|
|
|
|
hidden: false
|
|
|
|
|
experimental: false
|
|
|
|
|
experimentalcli: false
|
|
|
|
|
kubernetes: false
|
|
|
|
|
swarm: false
|
|
|
|
|
- option: no-TTY
|
|
|
|
|
shorthand: T
|
|
|
|
|
value_type: bool
|
|
|
|
|
default_value: "true"
|
|
|
|
|
description: 'Disable pseudo-TTY allocation (default: auto-detected).'
|
|
|
|
|
deprecated: false
|
|
|
|
|
hidden: false
|
|
|
|
|
experimental: false
|
|
|
|
|
experimentalcli: false
|
|
|
|
|
kubernetes: false
|
|
|
|
|
swarm: false
|
|
|
|
|
- option: no-deps
|
|
|
|
|
value_type: bool
|
|
|
|
|
default_value: "false"
|
|
|
|
|
description: Don't start linked services.
|
|
|
|
|
deprecated: false
|
|
|
|
|
hidden: false
|
|
|
|
|
experimental: false
|
|
|
|
|
experimentalcli: false
|
|
|
|
|
kubernetes: false
|
|
|
|
|
swarm: false
|
|
|
|
|
- option: publish
|
|
|
|
|
shorthand: p
|
|
|
|
|
value_type: stringArray
|
|
|
|
|
default_value: '[]'
|
|
|
|
|
description: Publish a container's port(s) to the host.
|
|
|
|
|
deprecated: false
|
|
|
|
|
hidden: false
|
|
|
|
|
experimental: false
|
|
|
|
|
experimentalcli: false
|
|
|
|
|
kubernetes: false
|
|
|
|
|
swarm: false
|
|
|
|
|
- option: quiet-pull
|
|
|
|
|
value_type: bool
|
|
|
|
|
default_value: "false"
|
|
|
|
|
description: Pull without printing progress information.
|
|
|
|
|
deprecated: false
|
|
|
|
|
hidden: false
|
|
|
|
|
experimental: false
|
|
|
|
|
experimentalcli: false
|
|
|
|
|
kubernetes: false
|
|
|
|
|
swarm: false
|
|
|
|
|
- option: rm
|
|
|
|
|
value_type: bool
|
|
|
|
|
default_value: "false"
|
|
|
|
|
description: Automatically remove the container when it exits
|
|
|
|
|
deprecated: false
|
|
|
|
|
hidden: false
|
|
|
|
|
experimental: false
|
|
|
|
|
experimentalcli: false
|
|
|
|
|
kubernetes: false
|
|
|
|
|
swarm: false
|
|
|
|
|
- option: service-ports
|
|
|
|
|
value_type: bool
|
|
|
|
|
default_value: "false"
|
|
|
|
|
description: |
|
|
|
|
|
Run command with the service's ports enabled and mapped to the host.
|
|
|
|
|
deprecated: false
|
|
|
|
|
hidden: false
|
|
|
|
|
experimental: false
|
|
|
|
|
experimentalcli: false
|
|
|
|
|
kubernetes: false
|
|
|
|
|
swarm: false
|
|
|
|
|
- option: tty
|
|
|
|
|
shorthand: t
|
|
|
|
|
value_type: bool
|
|
|
|
|
default_value: "true"
|
|
|
|
|
description: Allocate a pseudo-TTY.
|
|
|
|
|
deprecated: false
|
|
|
|
|
hidden: true
|
|
|
|
|
experimental: false
|
|
|
|
|
experimentalcli: false
|
|
|
|
|
kubernetes: false
|
|
|
|
|
swarm: false
|
|
|
|
|
- option: use-aliases
|
|
|
|
|
value_type: bool
|
|
|
|
|
default_value: "false"
|
|
|
|
|
description: |
|
|
|
|
|
Use the service's network useAliases in the network(s) the container connects to.
|
|
|
|
|
deprecated: false
|
|
|
|
|
hidden: false
|
|
|
|
|
experimental: false
|
|
|
|
|
experimentalcli: false
|
|
|
|
|
kubernetes: false
|
|
|
|
|
swarm: false
|
|
|
|
|
- option: user
|
|
|
|
|
shorthand: u
|
|
|
|
|
value_type: string
|
|
|
|
|
description: Run as specified username or uid
|
|
|
|
|
deprecated: false
|
|
|
|
|
hidden: false
|
|
|
|
|
experimental: false
|
|
|
|
|
experimentalcli: false
|
|
|
|
|
kubernetes: false
|
|
|
|
|
swarm: false
|
|
|
|
|
- option: volume
|
|
|
|
|
shorthand: v
|
|
|
|
|
value_type: stringArray
|
|
|
|
|
default_value: '[]'
|
|
|
|
|
description: Bind mount a volume.
|
|
|
|
|
deprecated: false
|
|
|
|
|
hidden: false
|
|
|
|
|
experimental: false
|
|
|
|
|
experimentalcli: false
|
|
|
|
|
kubernetes: false
|
|
|
|
|
swarm: false
|
|
|
|
|
- option: workdir
|
|
|
|
|
shorthand: w
|
|
|
|
|
value_type: string
|
|
|
|
|
description: Working directory inside the container
|
|
|
|
|
deprecated: false
|
|
|
|
|
hidden: false
|
|
|
|
|
experimental: false
|
|
|
|
|
experimentalcli: false
|
|
|
|
|
kubernetes: false
|
|
|
|
|
swarm: false
|
2023-01-11 16:19:02 +01:00
|
|
|
|
- option: remove-orphans
|
|
|
|
|
value_type: bool
|
|
|
|
|
default_value: "false"
|
|
|
|
|
description: Remove containers for services not defined in the Compose file.
|
|
|
|
|
deprecated: false
|
|
|
|
|
hidden: false
|
|
|
|
|
experimental: false
|
|
|
|
|
experimentalcli: false
|
|
|
|
|
kubernetes: false
|
|
|
|
|
swarm: false
|
2021-03-08 15:47:24 +01:00
|
|
|
|
deprecated: false
|
|
|
|
|
experimental: false
|
|
|
|
|
experimentalcli: false
|
|
|
|
|
kubernetes: false
|
|
|
|
|
swarm: false
|
2023-01-11 18:24:15 +01:00
|
|
|
|
|