1
0
Fork 0
mirror of https://github.com/tldr-pages/tldr.git synced 2025-04-29 23:24:55 +02:00
tldr/pages/common/docker-exec.md

29 lines
1.1 KiB
Markdown
Raw Normal View History

2020-10-07 07:45:08 -04:00
# docker exec
> Execute a command on an already running Docker container.
> More information: <https://docs.docker.com/reference/cli/docker/container/exec/>.
2020-10-07 07:45:08 -04:00
- Enter an interactive shell session on an already-running container:
`docker exec {{[-it|--interactive --tty]}} {{container_name}} {{/bin/bash}}`
2020-10-07 07:45:08 -04:00
- Run a command in the background (detached) on a running container:
`docker exec {{[-d|--detach]}} {{container_name}} {{command}}`
2020-10-07 07:45:08 -04:00
- Select the working directory for a given command to execute into:
`docker exec {{[-it|--interactive --tty]}} {{[-w|--workdir]}} {{path/to/directory}} {{container_name}} {{command}}`
2020-10-07 07:45:08 -04:00
- Run a command in background on existing container but keep `stdin` open:
2020-10-07 07:45:08 -04:00
`docker exec {{[-i|--interactive]}} {{[-d|--detach]}} {{container_name}} {{command}}`
2020-10-07 07:45:08 -04:00
- Set an environment variable in a running Bash session:
2020-10-07 07:45:08 -04:00
`docker exec {{[-it|--interactive --tty]}} {{[-e|--env]}} {{variable_name}}={{value}} {{container_name}} {{/bin/bash}}`
- Run a command as a specific user:
`docker exec {{[-u|--user]}} {{user}} {{container_name}} {{command}}`