Skip to content
LatchkeyLatchkey home

docker exec: Run Commands in a Container

Run a command inside an already-running container.

docker exec runs a new process inside a running container. It is how you open a shell to inspect a live container. This page covers the flags and the TTY pitfalls in CI.

What it does

docker exec starts an additional process in an existing, running container. The container must be running - exec cannot start a stopped one (use docker start for that).

Common usage

Terminal
docker exec -it web sh
docker exec -it db psql -U postgres
docker exec -u root web apt-get update
docker exec -e DEBUG=1 web env

Common errors in CI

In CI, docker exec -it fails with "the input device is not a TTY"; drop -t and use docker exec -i (or neither flag) for non-interactive scripts. "Error: No such container" usually means the container name is wrong or it already exited - check docker ps -a. "OCI runtime exec failed: ... executable file not found" means the binary (e.g. bash) is not in the image; try sh instead.

Frequently asked questions

docker exec: Run Commands in a Container?
docker exec runs a new process inside a running container. It is how you open a shell to inspect a live container. This page covers the flags and the TTY pitfalls in CI.
What it does?
docker exec starts an additional process in an existing, running container. The container must be running - exec cannot start a stopped one (use docker start for that).
Common errors in CI?
In CI, docker exec -it fails with "the input device is not a TTY"; drop -t and use docker exec -i (or neither flag) for non-interactive scripts. "Error: No such container" usually means the container name is wrong or it already exited - check docker ps -a. "OCI runtime exec failed: ... executable file not found" means the binary (e.g.

Related guides

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card