docker compose exec: Run a Command in a Service
Run a command inside a running service container.
docker compose exec runs a command in an already-running service by name. This page covers the -T flag CI needs and how it differs from compose run.
What it does
docker compose exec executes a command in the running container of a service (like docker exec but addressed by service name). The service must already be up. Contrast docker compose run, which starts a fresh one-off container.
Common usage
docker compose exec api sh
docker compose exec -T db psql -U postgres -c "select 1"
docker compose exec -T api npm run migrateCommon errors in CI
compose exec allocates a TTY by default, so in CI it fails with "the input device is not a TTY" - pass -T to disable the pseudo-TTY in pipelines. "service X is not running" means up has not started it (or it crashed); bring it up first. If you want a fresh container rather than the running one, use docker compose run.