docker-container-exec

execute a command in a running container

TLDR

Execute a command in a container
$ docker container exec [container] [command]
Start an interactive shell in a container
$ docker container exec -it [container] /bin/bash
Run a command as a specific user
$ docker container exec -u [user] [container] [command]
Set environment variables and execute a command
$ docker container exec -e [VAR=value] [container] [command]
Execute a command in a specific working directory
$ docker container exec -w [/path] [container] [command]
Run a command in the background (detached)
$ docker container exec -d [container] [command]
Load environment variables from a file
$ docker container exec --env-file [env.list] [container] [command]

SYNOPSIS

docker container exec [options] container command [args...]

DESCRIPTION

docker container exec runs a new command in a running container. The command runs in the default working directory of the container or the directory specified with --workdir. The command must be an executable; chained or quoted commands do not work.This is the long form of docker exec and behaves identically.

PARAMETERS

-i, --interactive

Keep STDIN open even if not attached.
-t, --tty
Allocate a pseudo-TTY.
-u, --user user
Username or UID (format: user, user:group, uid, uid:gid).
-w, --workdir dir
Working directory inside the container.
-e, --env list
Set environment variables.
--env-file file
Read environment variables from a file.
-d, --detach
Run command in the background.
--detach-keys string
Override the key sequence for detaching a container.
--privileged
Give extended privileges to the command.

INSTALL

sudo apt install docker-cli
sudo dnf install docker-cli
sudo pacman -S docker
sudo apk add docker-cli
sudo zypper install docker
brew install docker
nix profile install nixpkgs#docker

SEE ALSO

docker-exec(1), docker-container(1), docker-container-run(1), docker-run(1), podman-exec(1)