# docker exec Command Reference

> Reference for docker exec in CI: run a command inside a running container with -e, -w, -u, and -i to drive migrations, tests, or debugging in pipelines.

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

Run a command inside a running container.

docker exec executes a new process inside an already-running container. In CI it drives database migrations, runs test suites against a service container, or inspects state for debugging. Drop -t in pipelines to avoid TTY errors.

## Common flags

- `-i, --interactive` - keep stdin open
- `-t, --tty` - allocate a TTY (omit in non-interactive CI)
- `-e KEY=value` - set an environment variable for the exec
- `-w, --workdir` - working directory for the command
- `-u, --user` - user to run as inside the container
- `-d, --detach` - run the command in the background

## Example

```shell
docker exec -e RAILS_ENV=test app-web bin/rails db:migrate
docker exec -w /app -u node app-web npm run lint
```

## In CI

Use docker exec (without -t) to run migrations or tests inside a service container started by docker run -d or compose up -d. Adding -t in a pipeline triggers "the input device is not a TTY"; use -i alone or neither.

## FAQ

### docker exec Command Reference?

docker exec executes a new process inside an already-running container. In CI it drives database migrations, runs test suites against a service container, or inspects state for debugging. Drop -t in pipelines to avoid TTY errors.

### In CI?

Use docker exec (without -t) to run migrations or tests inside a service container started by docker run -d or compose up -d. Adding -t in a pipeline triggers "the input device is not a TTY"; use -i alone or neither.

---

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
