LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

docker-exec

execute commands in a running container

TLDR

Run command in container
$ docker exec [container] [command]
copy
Open interactive shell
$ docker exec -it [container] /bin/bash
copy
Run as specific user
$ docker exec -u [root] [container] [command]
copy
Set environment variable
$ docker exec -e [VAR=value] [container] [command]
copy
Run in specific directory
$ docker exec -w [/path] [container] [command]
copy

SYNOPSIS

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

DESCRIPTION

docker exec runs a new command in a running container's existing environment, creating a new process within the container's namespaces and cgroups. This is fundamentally different from docker run, which creates an entirely new container.The most common use case is opening an interactive shell for debugging with docker exec -it container /bin/bash, which provides direct access to the container's filesystem and running processes. Commands executed via docker exec inherit the container's environment but can be customized with user, working directory, and environment variable options.The --privileged flag grants extended capabilities useful for system administration tasks, though it should be used cautiously as it reduces container isolation.

PARAMETERS

-d, --detach

Run command in background.
-i, --interactive
Keep STDIN open.
-t, --tty
Allocate pseudo-TTY.
-u, --user user
Username or UID.
-w, --workdir dir
Working directory inside container.
-e, --env list
Set environment variables.
--env-file file
Read environment variables from a file.
--detach-keys sequence
Override the key sequence for detaching from the container.
--privileged
Give extended privileges.

INSTALL

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

CAVEATS

The container must be running. Commands inherit the container's environment. Use -it together for interactive shells. The --privileged flag reduces container isolation and should be used sparingly.

SEE ALSO

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid