Skip to content
Latchkey

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 test

In 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →