---
name: "docker-compose-exec"
section: "1"
platform: "linux"
package: "docker-compose"
version: "2.26.1-4"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/docker-compose-exec"
---

# docker-compose-exec(1)

Execute a command in a running container

## NAME

docker-compose-exec - Execute a command in a running container

## SYNOPSIS

**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

**-d**, **--detach**\[=false\]\
 	Detached mode: Run command in the background

**-e**, **--env**=\[\]\
 	Set environment variables

**-h**, **--help**\[=false\]\
 	help for exec

**--index**=0\
 	Index of the container if service has multiple replicas

**-T**, **--no-TTY**\[=true\]\
 	Disable pseudo-TTY allocation. By default **docker compose exec** allocates a TTY.

**--privileged**\[=false\]\
 	Give extended privileges to the process

**-u**, **--user**=""\
 	Run the command as this user

**-w**, **--workdir**=""\
 	Path to workdir directory for this command

## OPTIONS INHERITED FROM PARENT COMMANDS

**--dry-run**\[=false\]\
 	Execute command in dry run mode

## SEE ALSO

**[docker-compose(1)](/docker-compose/1.md)**
