Docker exec: run a command in a running container
Answer: The docker exec command runs a new command in a running container. The alias docker container exec is the same command. The command runs in the default working directory of the container.
Examples
docker exec -it myctr sh
docker container exec -w /tmp myctr ls
Notes
The exec command lives only while the container primary process (PID 1) is running, and it is not started again if the container is restarted. The command must be an executable. A chained or a quoted command does not work.
Reference list
dockerexec runs a new command in a running container.Thecommand runs in the container default working directory.
See also
Claims
- id: C1 claim: docker exec runs a new command in a running container. source: S1 evidence: "The docker exec command runs a new command in a running container"
- id: C2 claim: The command runs in the container default working directory. source: S1 evidence: "The command runs in the default working directory of the container"
- id: C3 claim: The CLI reference uses the same running-container wording. source: S2 evidence: "The
docker execcommand runs a new command in a running container"
Sources
- [S1] docker container exec. Docker docs. https://docs.docker.com/reference/cli/docker/container/exec/ . License: Apache-2.0. Accessed 2026-11-18.
- [S2] container exec reference. docker/cli. https://github.com/docker/cli/blob/master/docs/reference/commandline/container_exec.md . License: Apache-2.0. Accessed 2026-11-18.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Docker docs, docker container exec; docker/cli, container exec reference. Apache-2.0 (https://raw.githubusercontent.com/docker/docs/main/LICENSE). Copyright Docker, Inc. Apache-2.0 (https://raw.githubusercontent.com/docker/cli/master/LICENSE). Copyright Docker, Inc. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Docker docs, docker container exec; docker/cli, container exec reference. Apache-2.0 (https://raw.githubusercontent.com/docker/docs/main/LICENSE). Copyright Docker, Inc. Apache-2.0 (https://raw.githubusercontent.com/docker/cli/master/LICENSE). Copyright Docker, Inc.
Cite this
iinventedlight. 2026. "Docker exec: run a command in a running container." iinventedlight Library, iil:note:s0my6z6n, version of 2026-11-18. https://iinventedlight.com/library/notes/docker-exec/. License: CC-BY-4.0.
@misc{iil_note_s0my6z6n,
author = {{iinventedlight}},
title = {{Docker exec: run a command in a running container}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-18},
url = {https://iinventedlight.com/library/notes/docker-exec/},
note = {Permanent ID iil:note:s0my6z6n. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/docker-exec.md.