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
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.
Key takeaways
exec runs in an existing container; run starts a new one.
Omit -t in CI to avoid TTY allocation errors.
-w and -u control the working directory and user for the command.
Frequently asked questions
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.