Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

docker compose run command

docker compose run command

Docker Command ReferenceDocker Command Reference


The docker compose run command starts a new container and runs a specific service, without starting all services defined in the entire Compose file.

The docker compose run command lets you perform tasks on a single service, such as running one-off commands or debugging.

The difference from docker compose up is that the run command only runs the specified service and does not start other services it depends on.

Syntax

docker compose run [OPTIONS] SERVICE [COMMAND] [ARGS...]

OPTIONS:

Example

1. Run a command for a specific service



docker compose run web python manage.py migrate

This command executes python manage.py migrate in the web service's container without starting other services.

** 2. Automatically remove the container**



docker compose run --rm web bash

This command runs the web service and starts a Bash terminal, then removes the container after the task completes.

docker compose run is ideal for performing one-off tasks in a service without affecting the operation of other services.


Docker Command ReferenceDocker Command Reference