github.com/justincormack/cli@v0.0.0-20201215022714-831ebeae9675/man/src/container/exec.md (about)

     1  Run a process in a running container.
     2  
     3  The command started using `docker exec` will only run while the container's primary
     4  process (`PID 1`) is running, and will not be restarted if the container is restarted.
     5  
     6  If the container is paused, then the `docker exec` command will wait until the
     7  container is unpaused, and then run
     8  
     9  # CAPABILITIES
    10  
    11  `privileged` gives the process extended
    12  [Linux capabilities](http://man7.org/linux/man-pages/man7/capabilities.7.html)
    13  when running in a container. 
    14  
    15  Without this flag, the process run by `docker exec` in a running container has
    16  the same capabilities as the container, which may be limited. Set
    17  `--privileged` to give all capabilities to the process.
    18  
    19  # USER
    20  `user` sets the username or UID used and optionally the groupname or GID for the specified command.
    21  
    22     The followings examples are all valid:
    23     --user [user | user:group | uid | uid:gid | user:gid | uid:group ]
    24  
    25     Without this argument the command will be run as root in the container.
    26  
    27  # Exit Status
    28  
    29  The exit code from `docker exec` gives information about why the container
    30  failed to exec or why it exited.  When `docker exec` exits with a non-zero code,
    31  the exit codes follow the `chroot` standard, see below:
    32  
    33  **_126_** if the **_contained command_** cannot be invoked
    34  
    35      $ docker exec busybox /etc; echo $?
    36      # exec: "/etc": permission denied
    37        docker: Error response from daemon: Contained command could not be invoked
    38        126
    39  
    40  **_127_** if the **_contained command_** cannot be found
    41  
    42      $ docker exec busybox foo; echo $?
    43      # exec: "foo": executable file not found in $PATH
    44        docker: Error response from daemon: Contained command not found or does not exist
    45        127
    46  
    47  **_Exit code_** of **_contained command_** otherwise 
    48      
    49      $ docker exec busybox /bin/sh -c 'exit 3' 
    50      # 3
    51