diff options
| author | Craig Jennings <c@cjennings.net> | 2025-08-14 22:58:58 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2025-08-14 22:58:58 -0500 |
| commit | 82ba818ff456bcd6d56a06226e3f27e98fbb55c3 (patch) | |
| tree | 158cfc17b2f644a10f063cb546752cfaae12c97f /devdocs/docker/engine%2Freference%2Fcommandline%2Fexec%2Findex.html | |
| parent | 9278ddd4ea1a8b1a4c1edaa8894516e3f48d245b (diff) | |
| download | dotemacs-82ba818ff456bcd6d56a06226e3f27e98fbb55c3.tar.gz dotemacs-82ba818ff456bcd6d56a06226e3f27e98fbb55c3.zip | |
removing all downloaded devdocs files
Diffstat (limited to 'devdocs/docker/engine%2Freference%2Fcommandline%2Fexec%2Findex.html')
| -rw-r--r-- | devdocs/docker/engine%2Freference%2Fcommandline%2Fexec%2Findex.html | 42 |
1 files changed, 0 insertions, 42 deletions
diff --git a/devdocs/docker/engine%2Freference%2Fcommandline%2Fexec%2Findex.html b/devdocs/docker/engine%2Freference%2Fcommandline%2Fexec%2Findex.html deleted file mode 100644 index 9e9de22f..00000000 --- a/devdocs/docker/engine%2Freference%2Fcommandline%2Fexec%2Findex.html +++ /dev/null @@ -1,42 +0,0 @@ -<h1>docker exec</h1> <p><br></p> <p>Run a command in a running container</p> <h2 id="usage">Usage</h2> <div class="highlight"><pre class="highlight" data-language="">$ docker exec [OPTIONS] CONTAINER COMMAND [ARG...] -</pre></div> <p>Refer to the <a href="#options">options section</a> for an overview of available <a href="#options"><code class="language-plaintext highlighter-rouge">OPTIONS</code></a> for this command.</p> <h2 id="description">Description</h2> <p name="extended-description">The <code class="language-plaintext highlighter-rouge">docker exec</code> command runs a new command in a running container.</p> <p>The command started using <code class="language-plaintext highlighter-rouge">docker exec</code> only runs while the container’s primary process (<code class="language-plaintext highlighter-rouge">PID 1</code>) is running, and it is not restarted if the container is restarted.</p> <p>COMMAND will run in the default directory of the container. If the underlying image has a custom directory specified with the WORKDIR directive in its Dockerfile, this will be used instead.</p> <p>COMMAND should be an executable, a chained or a quoted command will not work. Example: <code class="language-plaintext highlighter-rouge">docker exec -ti my_container "echo a && echo b"</code> will not work, but <code class="language-plaintext highlighter-rouge">docker exec -ti my_container sh -c "echo a && echo b"</code> will.</p> <p>For example uses of this command, refer to the <a href="#examples">examples section</a> below.</p> <h2 id="options">Options</h2> <table> <thead> <tr> <td>Name, shorthand</td> <td>Default</td> <td>Description</td> </tr> </thead> <tbody> <tr> <td> -<code class="language-plaintext highlighter-rouge">--detach</code> , <code class="language-plaintext highlighter-rouge">-d</code> -</td> <td></td> <td>Detached mode: run command in the background</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--detach-keys</code></td> <td></td> <td>Override the key sequence for detaching a container</td> </tr> <tr> <td> -<code class="language-plaintext highlighter-rouge">--env</code> , <code class="language-plaintext highlighter-rouge">-e</code> -</td> <td></td> <td>Set environment variables</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--env-file</code></td> <td></td> <td>Read in a file of environment variables</td> </tr> <tr> <td> -<code class="language-plaintext highlighter-rouge">--interactive</code> , <code class="language-plaintext highlighter-rouge">-i</code> -</td> <td></td> <td>Keep STDIN open even if not attached</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--privileged</code></td> <td></td> <td>Give extended privileges to the command</td> </tr> <tr> <td> -<code class="language-plaintext highlighter-rouge">--tty</code> , <code class="language-plaintext highlighter-rouge">-t</code> -</td> <td></td> <td>Allocate a pseudo-TTY</td> </tr> <tr> <td> -<code class="language-plaintext highlighter-rouge">--user</code> , <code class="language-plaintext highlighter-rouge">-u</code> -</td> <td></td> <td>Username or UID (format: <name|uid>[:<group|gid>])</td> </tr> <tr> <td> -<code class="language-plaintext highlighter-rouge">--workdir</code> , <code class="language-plaintext highlighter-rouge">-w</code> -</td> <td></td> <td>Working directory inside the container</td> </tr> </tbody> </table> <h2 id="examples">Examples</h2> <h3 id="run-docker-exec-on-a-running-container">Run <code class="language-plaintext highlighter-rouge">docker exec</code> on a running container</h3> <p>First, start a container.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run --name ubuntu_bash --rm -i -t ubuntu bash -</pre></div> <p>This will create a container named <code class="language-plaintext highlighter-rouge">ubuntu_bash</code> and start a Bash session.</p> <p>Next, execute a command on the container.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker exec -d ubuntu_bash touch /tmp/execWorks -</pre></div> <p>This will create a new file <code class="language-plaintext highlighter-rouge">/tmp/execWorks</code> inside the running container <code class="language-plaintext highlighter-rouge">ubuntu_bash</code>, in the background.</p> <p>Next, execute an interactive <code class="language-plaintext highlighter-rouge">bash</code> shell on the container.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker exec -it ubuntu_bash bash -</pre></div> <p>This will create a new Bash session in the container <code class="language-plaintext highlighter-rouge">ubuntu_bash</code>.</p> <p>Next, set an environment variable in the current bash session.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker exec -it -e VAR=1 ubuntu_bash bash -</pre></div> <p>This will create a new Bash session in the container <code class="language-plaintext highlighter-rouge">ubuntu_bash</code> with environment variable <code class="language-plaintext highlighter-rouge">$VAR</code> set to “1”. Note that this environment variable will only be valid on the current Bash session.</p> <p>By default <code class="language-plaintext highlighter-rouge">docker exec</code> command runs in the same working directory set when container was created.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker exec -it ubuntu_bash pwd -/ -</pre></div> <p>You can select working directory for the command to execute into</p> <div class="highlight"><pre class="highlight" data-language="">$ docker exec -it -w /root ubuntu_bash pwd -/root -</pre></div> <h3 id="try-to-run-docker-exec-on-a-paused-container">Try to run <code class="language-plaintext highlighter-rouge">docker exec</code> on a paused container</h3> <p>If the container is paused, then the <code class="language-plaintext highlighter-rouge">docker exec</code> command will fail with an error:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker pause test - -test - -$ docker ps - -CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -1ae3b36715d2 ubuntu:latest "bash" 17 seconds ago Up 16 seconds (Paused) test - -$ docker exec test ls - -FATA[0000] Error response from daemon: Container test is paused, unpause the container before exec - -$ echo $? -1 -</pre></div> <div class="_attribution"> - <p class="_attribution-p"> - © 2019 Docker, Inc.<br>Licensed under the Apache License, Version 2.0.<br>Docker and the Docker logo are trademarks or registered trademarks of Docker, Inc. in the United States and/or other countries.<br>Docker, Inc. and other parties may also have trademark rights in other terms used herein.<br> - <a href="https://docs.docker.com/engine/reference/commandline/exec/" class="_attribution-link">https://docs.docker.com/engine/reference/commandline/exec/</a> - </p> -</div> |
