.nh .TH "DOCKER" "1" "May 2022" "Docker Community" "Docker User Manuals" .SH NAME .PP docker\-container\-exec \- Run a command in a running container .SH SYNOPSIS .PP \fBdocker container exec [OPTIONS] CONTAINER COMMAND [ARG...]\fP .SH DESCRIPTION .PP Run a process in a running container. .PP The command started using \fB\fCdocker exec\fR will only run while the container's primary process (\fB\fCPID 1\fR) is running, and will not be restarted if the container is restarted. .PP If the container is paused, then the \fB\fCdocker exec\fR command will wait until the container is unpaused, and then run .SH CAPABILITIES .PP \fB\fCprivileged\fR gives the process extended Linux capabilities \[la]http://man7.org/linux/man-pages/man7/capabilities.7.html\[ra] when running in a container. .PP Without this flag, the process run by \fB\fCdocker exec\fR in a running container has the same capabilities as the container, which may be limited. Set \fB\fC\-\-privileged\fR to give all capabilities to the process. .SH USER .PP \fB\fCuser\fR sets the username or UID used and optionally the groupname or GID for the specified command. .PP The followings examples are all valid: \-\-user [user | user:group | uid | uid:gid | user:gid | uid:group ] .PP Without this argument the command will be run as root in the container. .SH Exit Status .PP The exit code from \fB\fCdocker exec\fR gives information about why the container failed to exec or why it exited. When \fB\fCdocker exec\fR exits with a non\-zero code, the exit codes follow the \fB\fCchroot\fR standard, see below: .PP \fB\fI126\fP\fP if the \fB\fIcontained command\fP\fP cannot be invoked .PP .RS .nf $ docker exec busybox /etc; echo $? # exec: "/etc": permission denied docker: Error response from daemon: Contained command could not be invoked 126 .fi .RE .PP \fB\fI127\fP\fP if the \fB\fIcontained command\fP\fP cannot be found .PP .RS .nf $ docker exec busybox foo; echo $? # exec: "foo": executable file not found in $PATH docker: Error response from daemon: Contained command not found or does not exist 127 .fi .RE .PP \fB\fIExit code\fP\fP of \fB\fIcontained command\fP\fP otherwise .PP .RS .nf $ docker exec busybox /bin/sh \-c 'exit 3' # 3 .fi .RE .SH OPTIONS .PP \fB\-d\fP, \fB\-\-detach\fP[=false] Detached mode: run command in the background .PP \fB\-\-detach\-keys\fP="" Override the key sequence for detaching a container .PP \fB\-e\fP, \fB\-\-env\fP= Set environment variables .PP \fB\-\-env\-file\fP= Read in a file of environment variables .PP \fB\-h\fP, \fB\-\-help\fP[=false] help for exec .PP \fB\-i\fP, \fB\-\-interactive\fP[=false] Keep STDIN open even if not attached .PP \fB\-\-privileged\fP[=false] Give extended privileges to the command .PP \fB\-t\fP, \fB\-\-tty\fP[=false] Allocate a pseudo\-TTY .PP \fB\-u\fP, \fB\-\-user\fP="" Username or UID (format: [:]) .PP \fB\-w\fP, \fB\-\-workdir\fP="" Working directory inside the container .SH SEE ALSO .PP \fBdocker\-container(1)\fP