LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

docker-container-exec

execute a command in a running container

TLDR

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

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.

SEE ALSO

Copied to clipboard
Kai