github.com/flavio/docker@v0.1.3-0.20170117145210-f63d1a6eec47/docs/reference/commandline/exec.md (about) 1 --- 2 title: "exec" 3 description: "The exec command description and usage" 4 keywords: "command, container, run, execute" 5 --- 6 7 <!-- This file is maintained within the docker/docker Github 8 repository at https://github.com/docker/docker/. Make all 9 pull requests against that repo. If you see this file in 10 another repository, consider it read-only there, as it will 11 periodically be overwritten by the definitive file. Pull 12 requests which include edits to this file in other repositories 13 will be rejected. 14 --> 15 16 # exec 17 18 ```markdown 19 Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...] 20 21 Run a command in a running container 22 23 Options: 24 -d, --detach Detached mode: run command in the background 25 --detach-keys Override the key sequence for detaching a container 26 -e, --env=[] Set environment variables 27 --help Print usage 28 -i, --interactive Keep STDIN open even if not attached 29 --privileged Give extended privileges to the command 30 -t, --tty Allocate a pseudo-TTY 31 -u, --user Username or UID (format: <name|uid>[:<group|gid>]) 32 ``` 33 34 The `docker exec` command runs a new command in a running container. 35 36 The command started using `docker exec` only runs while the container's primary 37 process (`PID 1`) is running, and it is not restarted if the container is 38 restarted. 39 40 If the container is paused, then the `docker exec` command will fail with an error: 41 42 $ docker pause test 43 test 44 $ docker ps 45 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 46 1ae3b36715d2 ubuntu:latest "bash" 17 seconds ago Up 16 seconds (Paused) test 47 $ docker exec test ls 48 FATA[0000] Error response from daemon: Container test is paused, unpause the container before exec 49 $ echo $? 50 1 51 52 ## Examples 53 54 $ docker run --name ubuntu_bash --rm -i -t ubuntu bash 55 56 This will create a container named `ubuntu_bash` and start a Bash session. 57 58 $ docker exec -d ubuntu_bash touch /tmp/execWorks 59 60 This will create a new file `/tmp/execWorks` inside the running container 61 `ubuntu_bash`, in the background. 62 63 $ docker exec -it ubuntu_bash bash 64 65 This will create a new Bash session in the container `ubuntu_bash`.