docker compose exec
Execute a command in a running container.
Usage
docker compose exec [OPTIONS] SERVICE COMMAND [ARGS...]
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.
Options
Option | Short | Default | Description |
---|---|---|---|
--detach | -d | Detached mode: Run command in the background. | |
--env | -e | Set environment variables | |
--index | index of the container if service has multiple replicas | ||
--interactive | -i | true | Keep STDIN open even if not attached. |
--no-TTY | -T | true | Disable pseudo-TTY allocation. By default docker compose exec allocates a TTY. |
--privileged | Give extended privileges to the process. | ||
--tty | -t | true | Allocate a pseudo-TTY. |
--user | -u | Run the command as this user. | |
--workdir | -w | Path to workdir directory for this command. |