github.com/vieux/docker@v0.6.3-0.20161004191708-e097c2a938c7/docs/reference/commandline/exec.md (about)

     1  <!--[metadata]>
     2  +++
     3  title = "exec"
     4  description = "The exec command description and usage"
     5  keywords = ["command, container, run, execute"]
     6  [menu.main]
     7  parent = "smn_cli"
     8  +++
     9  <![end-metadata]-->
    10  
    11  # exec
    12  
    13  ```markdown
    14  Usage:  docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
    15  
    16  Run a command in a running container
    17  
    18  Options:
    19    -d, --detach         Detached mode: run command in the background
    20        --detach-keys    Override the key sequence for detaching a container
    21        --help           Print usage
    22    -i, --interactive    Keep STDIN open even if not attached
    23        --privileged     Give extended privileges to the command
    24    -t, --tty            Allocate a pseudo-TTY
    25    -u, --user           Username or UID (format: <name|uid>[:<group|gid>])
    26  ```
    27  
    28  The `docker exec` command runs a new command in a running container.
    29  
    30  The command started using `docker exec` only runs while the container's primary
    31  process (`PID 1`) is running, and it is not restarted if the container is
    32  restarted.
    33  
    34  If the container is paused, then the `docker exec` command will fail with an error:
    35  
    36      $ docker pause test
    37      test
    38      $ docker ps
    39      CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                   PORTS               NAMES
    40      1ae3b36715d2        ubuntu:latest       "bash"              17 seconds ago      Up 16 seconds (Paused)                       test
    41      $ docker exec test ls
    42      FATA[0000] Error response from daemon: Container test is paused, unpause the container before exec
    43      $ echo $?
    44      1
    45  
    46  ## Examples
    47  
    48      $ docker run --name ubuntu_bash --rm -i -t ubuntu bash
    49  
    50  This will create a container named `ubuntu_bash` and start a Bash session.
    51  
    52      $ docker exec -d ubuntu_bash touch /tmp/execWorks
    53  
    54  This will create a new file `/tmp/execWorks` inside the running container
    55  `ubuntu_bash`, in the background.
    56  
    57      $ docker exec -it ubuntu_bash bash
    58  
    59  This will create a new Bash session in the container `ubuntu_bash`.