ScanSkill

docker compose exec

This is equivalent to docker exec. With this subcommand, you can run arbitrary commands in your services. Commands are by default allocating a TTY, so you can do e.g. docker-compose exec web sh to get an interactive prompt.

Syntax

$ docker compose exec [options] [-e KEY=VAL...] [--] SERVICE COMMAND [ARGS...]

Here,

OPTIONS:

  • --detach , -d → Detached mode: Run command in the background.
  • --env , -e → Set environment variables
  • --index → index of the container if there are multiple instances of service [default: 1].
  • --interactive , -i → Keep STDIN open even if not attached.
  • --no-TTY , -T → Disable pseudo-TTY allocation. By default docker-compose, exec allocates a TTY.
  • --privileged → Give extended privileges to the process.
  • --tty , -t → Allocate a pseudo-TTY.
  • --user , -u → Run the command as this user.
  • --workdir , -w → Path to the working directory for this command.