# docker exec: Run Commands in a Container

> How docker exec works: running a command in a running container, opening a shell, env and user flags, and the TTY errors in CI.

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

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.

## FAQ

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

---

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
