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