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