# docker compose exec: Run a Command in a Service

> How docker compose exec works: running a command in a running service container, the -T flag for CI, and not-running errors.

Source: https://latchkey.dev/learn/command-reference/docker-compose-exec  
Updated: 2026-06-25

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

```Terminal
docker compose exec api sh
docker compose exec -T db psql -U postgres -c "select 1"
docker compose exec -T api npm run migrate
```

## Common 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.

## FAQ

### docker compose exec: Run a Command in a Service?

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 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.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
