Debian Codegraph @

docs/reference/compose_exec.md

raw
1 # docker compose exec
2
3 <!---MARKER_GEN_START-->
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 allocate a TTY by default, so
7 you can use a command such as `docker compose exec web sh` to get an interactive prompt.
8
9 By default, Compose will enter container in interactive mode and allocate a TTY, while the equivalent `docker exec`
10 command requires passing `--interactive --tty` flags to get the same behavior. Compose also support those two flags
11 to offer a smooth migration between commands, whenever they are no-op by default. Still, `interactive` can be used to
12 force disabling interactive mode (`--interactive=false`), typically when `docker compose exec` command is used inside
13 a script.
14
15 ### Options
16
17 | Name | Type | Default | Description |
18 |:------------------|:--------------|:--------|:---------------------------------------------------------------------------------|
19 | `-d`, `--detach` | `bool` | | Detached mode: Run command in the background |
20 | `--dry-run` | `bool` | | Execute command in dry run mode |
21 | `-e`, `--env` | `stringArray` | | Set environment variables |
22 | `--index` | `int` | `0` | Index of the container if service has multiple replicas |
23 | `-T`, `--no-tty` | `bool` | `true` | Disable pseudo-TTY allocation. By default 'docker compose exec' allocates a TTY. |
24 | `--privileged` | `bool` | | Give extended privileges to the process |
25 | `-u`, `--user` | `string` | | Run the command as this user |
26 | `-w`, `--workdir` | `string` | | Path to workdir directory for this command |
27
28
29 <!---MARKER_GEN_END-->
30
31 ## Description
32
33 This is the equivalent of `docker exec` targeting a Compose service.
34
35 With this subcommand, you can run arbitrary commands in your services. Commands allocate a TTY by default, so
36 you can use a command such as `docker compose exec web sh` to get an interactive prompt.
37
38 By default, Compose will enter container in interactive mode and allocate a TTY, while the equivalent `docker exec`
39 command requires passing `--interactive --tty` flags to get the same behavior. Compose also support those two flags
40 to offer a smooth migration between commands, whenever they are no-op by default. Still, `interactive` can be used to
41 force disabling interactive mode (`--interactive=false`), typically when `docker compose exec` command is used inside
42 a script.