docker-exec
Execute a command on an already running Docker container.
TLDR
Enter an interactive shell session on an already-running container
$ docker exec --interactive --tty [container_name] [/bin/bash]
Run a command in the background (detached) on a running container
$ docker exec --detach [container_name] [command]
Select the working directory for a given command to execute into
$ docker exec --interactive -tty --workdir [path/to/directory] [container_name] [command]
Run a command in background on existing container but keep stdin open
$ docker exec --interactive --detach [container_name] [command]
Set an environment variable in a running Bash session
$ docker exec --interactive --tty --env [variable_name]=[value] [container_name] [/bin/bash]
Run a command as a specific user
$ docker exec --user [user] [container_name] [command]
SYNOPSIS
docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
DESCRIPTION
Alias for docker container exec
.
OPTIONS
-d, --detach[=false] Detached mode: run command in the background
--detach-keys="" Override the key sequence for detaching a container
-e, --env= Set environment variables
--env-file= Read in a file of environment variables
-h, --help[=false] help for exec
-i, --interactive[=false] Keep STDIN open even if not attached
--privileged[=false] Give extended privileges to the command
-t, --tty[=false] Allocate a pseudo-TTY
-u, --user="" Username or UID (format: [:])
-w, --workdir="" Working directory inside the container
SEE ALSO
docker(1)