Back to Compose

docker compose exec

docs/reference/compose_exec.md

5.1.32.8 KB
Original Source

docker compose exec

<!---MARKER_GEN_START-->

This is the equivalent of docker exec targeting a Compose service.

With this subcommand, you can run arbitrary commands in your services. Commands allocate a TTY by default, so you can use a command such as docker compose exec web sh to get an interactive prompt.

By default, Compose will enter container in interactive mode and allocate a TTY, while the equivalent docker exec command requires passing --interactive --tty flags to get the same behavior. Compose also support those two flags to offer a smooth migration between commands, whenever they are no-op by default. Still, interactive can be used to force disabling interactive mode (--interactive=false), typically when docker compose exec command is used inside a script.

Options

NameTypeDefaultDescription
-d, --detachboolDetached mode: Run command in the background
--dry-runboolExecute command in dry run mode
-e, --envstringArraySet environment variables
--indexint0Index of the container if service has multiple replicas
-T, --no-ttybooltrueDisable pseudo-TTY allocation. By default 'docker compose exec' allocates a TTY.
--privilegedboolGive extended privileges to the process
-u, --userstringRun the command as this user
-w, --workdirstringPath to workdir directory for this command
<!---MARKER_GEN_END-->

Description

This is the equivalent of docker exec targeting a Compose service.

With this subcommand, you can run arbitrary commands in your services. Commands allocate a TTY by default, so you can use a command such as docker compose exec web sh to get an interactive prompt.

By default, Compose will enter container in interactive mode and allocate a TTY, while the equivalent docker exec command requires passing --interactive --tty flags to get the same behavior. Compose also support those two flags to offer a smooth migration between commands, whenever they are no-op by default. Still, interactive can be used to force disabling interactive mode (--interactive=false), typically when docker compose exec command is used inside a script.