docker compose run Command Reference
Run a one-off command against a service.
docker compose run starts a new container for a service and runs a command in it, separate from the long-running service started by up. In CI it executes test suites, migrations, or scripts using the service image and its dependencies.
Common flags
--rm- remove the container after the command exits-e KEY=value- set an environment variable for the run--no-deps- do not start linked services-T- disable pseudo-TTY allocation (use in CI)-w, --workdir- working directory inside the container
Example
shell
docker compose run --rm -T -e CI=true app npm run testIn CI
Pass -T to disable the pseudo-TTY (the "the input device is not a TTY" fix for compose) and --rm so the throwaway container is cleaned up. Use --no-deps when the dependencies are already running from a prior compose up to avoid starting duplicates.
Key takeaways
- -T disables the TTY so compose run works in non-interactive CI.
- --rm cleans up the one-off container after the command exits.
- --no-deps avoids re-starting services already brought up by compose up.
Related guides
docker compose up Command ReferenceReference for docker compose up in CI: start services from a compose file with -d, --build, and --wait so dep…
docker compose exec Command ReferenceReference for docker compose exec in CI: run a command in a running service container with -T, -e, and -w to…
docker run Command ReferenceReference for docker run in CI: --rm, -e, -v, --network, -w, and --entrypoint flags for creating and starting…