diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/docker/engine%2Freference%2Fcommandline%2Fps%2Findex.html | |
new repository
Diffstat (limited to 'devdocs/docker/engine%2Freference%2Fcommandline%2Fps%2Findex.html')
| -rw-r--r-- | devdocs/docker/engine%2Freference%2Fcommandline%2Fps%2Findex.html | 172 |
1 files changed, 172 insertions, 0 deletions
diff --git a/devdocs/docker/engine%2Freference%2Fcommandline%2Fps%2Findex.html b/devdocs/docker/engine%2Freference%2Fcommandline%2Fps%2Findex.html new file mode 100644 index 00000000..72e25f21 --- /dev/null +++ b/devdocs/docker/engine%2Freference%2Fcommandline%2Fps%2Findex.html @@ -0,0 +1,172 @@ +<h1>docker ps</h1> <p><br></p> <p>List containers</p> <h2 id="usage">Usage</h2> <div class="highlight"><pre class="highlight" data-language="">$ docker ps [OPTIONS] +</pre></div> <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">--all</code> , <code class="language-plaintext highlighter-rouge">-a</code> +</td> <td></td> <td>Show all containers (default shows just running)</td> </tr> <tr> <td> +<code class="language-plaintext highlighter-rouge">--filter</code> , <code class="language-plaintext highlighter-rouge">-f</code> +</td> <td></td> <td>Filter output based on conditions provided</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--format</code></td> <td></td> <td>Pretty-print containers using a Go template</td> </tr> <tr> <td> +<code class="language-plaintext highlighter-rouge">--last</code> , <code class="language-plaintext highlighter-rouge">-n</code> +</td> <td><code class="language-plaintext highlighter-rouge">-1</code></td> <td>Show n last created containers (includes all states)</td> </tr> <tr> <td> +<code class="language-plaintext highlighter-rouge">--latest</code> , <code class="language-plaintext highlighter-rouge">-l</code> +</td> <td></td> <td>Show the latest created container (includes all states)</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--no-trunc</code></td> <td></td> <td>Don't truncate output</td> </tr> <tr> <td> +<code class="language-plaintext highlighter-rouge">--quiet</code> , <code class="language-plaintext highlighter-rouge">-q</code> +</td> <td></td> <td>Only display container IDs</td> </tr> <tr> <td> +<code class="language-plaintext highlighter-rouge">--size</code> , <code class="language-plaintext highlighter-rouge">-s</code> +</td> <td></td> <td>Display total file sizes</td> </tr> </tbody> </table> <h2 id="examples">Examples</h2> <h3 id="prevent-truncating-output">Prevent truncating output</h3> <p>Running <code class="language-plaintext highlighter-rouge">docker ps --no-trunc</code> showing 2 linked containers.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker ps + +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +4c01db0b339c ubuntu:12.04 bash 17 seconds ago Up 16 seconds 3300-3310/tcp webapp +d7886598dbe2 crosbymichael/redis:latest /redis-server --dir 33 minutes ago Up 33 minutes 6379/tcp redis,webapp/db +</pre></div> <h3 id="show-both-running-and-stopped-containers">Show both running and stopped containers</h3> <p>The <code class="language-plaintext highlighter-rouge">docker ps</code> command only shows running containers by default. To see all containers, use the <code class="language-plaintext highlighter-rouge">-a</code> (or <code class="language-plaintext highlighter-rouge">--all</code>) flag:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker ps -a +</pre></div> <p><code class="language-plaintext highlighter-rouge">docker ps</code> groups exposed ports into a single range if possible. E.g., a container that exposes TCP ports <code class="language-plaintext highlighter-rouge">100, 101, 102</code> displays <code class="language-plaintext highlighter-rouge">100-102/tcp</code> in the <code class="language-plaintext highlighter-rouge">PORTS</code> column.</p> <h3 id="show-disk-usage-by-container">Show disk usage by container</h3> <p>The <code class="language-plaintext highlighter-rouge">docker ps -s</code> command displays two different on-disk-sizes for each container:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker ps -s + +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZE SIZE +e90b8831a4b8 nginx "/bin/bash -c 'mkdir " 11 weeks ago Up 4 hours my_nginx 35.58 kB (virtual 109.2 MB) +00c6131c5e30 telegraf:1.5 "/entrypoint.sh" 11 weeks ago Up 11 weeks my_telegraf 0 B (virtual 209.5 MB) +</pre></div> <ul> <li>The “size” information shows the amount of data (on disk) that is used for the <em>writable</em> layer of each container</li> <li>The “virtual size” is the total amount of disk-space used for the read-only <em>image</em> data used by the container and the writable layer.</li> </ul> <p>For more information, refer to the <a href="https://docs.docker.com/storage/storagedriver/#container-size-on-disk">container size on disk</a> section.</p> <h3 id="filtering">Filtering</h3> <p>The filtering flag (<code class="language-plaintext highlighter-rouge">-f</code> or <code class="language-plaintext highlighter-rouge">--filter</code>) format is a <code class="language-plaintext highlighter-rouge">key=value</code> pair. If there is more than one filter, then pass multiple flags (e.g. <code class="language-plaintext highlighter-rouge">--filter "foo=bar" --filter "bif=baz"</code>)</p> <p>The currently supported filters are:</p> <table> <thead> <tr> <th style="text-align: left">Filter</th> <th style="text-align: left">Description</th> </tr> </thead> <tbody> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">id</code></td> <td style="text-align: left">Container’s ID</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">name</code></td> <td style="text-align: left">Container’s name</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">label</code></td> <td style="text-align: left">An arbitrary string representing either a key or a key-value pair. Expressed as <code class="language-plaintext highlighter-rouge"><key></code> or <code class="language-plaintext highlighter-rouge"><key>=<value></code> +</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">exited</code></td> <td style="text-align: left">An integer representing the container’s exit code. Only useful with <code class="language-plaintext highlighter-rouge">--all</code>.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">status</code></td> <td style="text-align: left">One of <code class="language-plaintext highlighter-rouge">created</code>, <code class="language-plaintext highlighter-rouge">restarting</code>, <code class="language-plaintext highlighter-rouge">running</code>, <code class="language-plaintext highlighter-rouge">removing</code>, <code class="language-plaintext highlighter-rouge">paused</code>, <code class="language-plaintext highlighter-rouge">exited</code>, or <code class="language-plaintext highlighter-rouge">dead</code> +</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">ancestor</code></td> <td style="text-align: left">Filters containers which share a given image as an ancestor. Expressed as <code class="language-plaintext highlighter-rouge"><image-name>[:<tag>]</code>, <code class="language-plaintext highlighter-rouge"><image id></code>, or <code class="language-plaintext highlighter-rouge"><image@digest></code> +</td> </tr> <tr> <td style="text-align: left"> +<code class="language-plaintext highlighter-rouge">before</code> or <code class="language-plaintext highlighter-rouge">since</code> +</td> <td style="text-align: left">Filters containers created before or after a given container ID or name</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">volume</code></td> <td style="text-align: left">Filters running containers which have mounted a given volume or bind mount.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">network</code></td> <td style="text-align: left">Filters running containers connected to a given network.</td> </tr> <tr> <td style="text-align: left"> +<code class="language-plaintext highlighter-rouge">publish</code> or <code class="language-plaintext highlighter-rouge">expose</code> +</td> <td style="text-align: left">Filters containers which publish or expose a given port. Expressed as <code class="language-plaintext highlighter-rouge"><port>[/<proto>]</code> or <code class="language-plaintext highlighter-rouge"><startport-endport>/[<proto>]</code> +</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">health</code></td> <td style="text-align: left">Filters containers based on their healthcheck status. One of <code class="language-plaintext highlighter-rouge">starting</code>, <code class="language-plaintext highlighter-rouge">healthy</code>, <code class="language-plaintext highlighter-rouge">unhealthy</code> or <code class="language-plaintext highlighter-rouge">none</code>.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">isolation</code></td> <td style="text-align: left">Windows daemon only. One of <code class="language-plaintext highlighter-rouge">default</code>, <code class="language-plaintext highlighter-rouge">process</code>, or <code class="language-plaintext highlighter-rouge">hyperv</code>.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">is-task</code></td> <td style="text-align: left">Filters containers that are a “task” for a service. Boolean option (<code class="language-plaintext highlighter-rouge">true</code> or <code class="language-plaintext highlighter-rouge">false</code>)</td> </tr> </tbody> </table> <h4 id="label">label</h4> <p>The <code class="language-plaintext highlighter-rouge">label</code> filter matches containers based on the presence of a <code class="language-plaintext highlighter-rouge">label</code> alone or a <code class="language-plaintext highlighter-rouge">label</code> and a value.</p> <p>The following filter matches containers with the <code class="language-plaintext highlighter-rouge">color</code> label regardless of its value.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker ps --filter "label=color" + +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +673394ef1d4c busybox "top" 47 seconds ago Up 45 seconds nostalgic_shockley +d85756f57265 busybox "top" 52 seconds ago Up 51 seconds high_albattani +</pre></div> <p>The following filter matches containers with the <code class="language-plaintext highlighter-rouge">color</code> label with the <code class="language-plaintext highlighter-rouge">blue</code> value.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker ps --filter "label=color=blue" + +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +d85756f57265 busybox "top" About a minute ago Up About a minute high_albattani +</pre></div> <h4 id="name">name</h4> <p>The <code class="language-plaintext highlighter-rouge">name</code> filter matches on all or part of a container’s name.</p> <p>The following filter matches all containers with a name containing the <code class="language-plaintext highlighter-rouge">nostalgic_stallman</code> string.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker ps --filter "name=nostalgic_stallman" + +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +9b6247364a03 busybox "top" 2 minutes ago Up 2 minutes nostalgic_stallman +</pre></div> <p>You can also filter for a substring in a name as this shows:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker ps --filter "name=nostalgic" + +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +715ebfcee040 busybox "top" 3 seconds ago Up 1 second i_am_nostalgic +9b6247364a03 busybox "top" 7 minutes ago Up 7 minutes nostalgic_stallman +673394ef1d4c busybox "top" 38 minutes ago Up 38 minutes nostalgic_shockley +</pre></div> <h4 id="exited">exited</h4> <p>The <code class="language-plaintext highlighter-rouge">exited</code> filter matches containers by exist status code. For example, to filter for containers that have exited successfully:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker ps -a --filter 'exited=0' + +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +ea09c3c82f6e registry:latest /srv/run.sh 2 weeks ago Exited (0) 2 weeks ago 127.0.0.1:5000->5000/tcp desperate_leakey +106ea823fe4e fedora:latest /bin/sh -c 'bash -l' 2 weeks ago Exited (0) 2 weeks ago determined_albattani +48ee228c9464 fedora:20 bash 2 weeks ago Exited (0) 2 weeks ago tender_torvalds +</pre></div> <h4 id="filter-by-exit-signal">Filter by exit signal</h4> <p>You can use a filter to locate containers that exited with status of <code class="language-plaintext highlighter-rouge">137</code> meaning a <code class="language-plaintext highlighter-rouge">SIGKILL(9)</code> killed them.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker ps -a --filter 'exited=137' + +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +b3e1c0ed5bfe ubuntu:latest "sleep 1000" 12 seconds ago Exited (137) 5 seconds ago grave_kowalevski +a2eb5558d669 redis:latest "/entrypoint.sh redi 2 hours ago Exited (137) 2 hours ago sharp_lalande +</pre></div> <p>Any of these events result in a <code class="language-plaintext highlighter-rouge">137</code> status:</p> <ul> <li>the <code class="language-plaintext highlighter-rouge">init</code> process of the container is killed manually</li> <li> +<code class="language-plaintext highlighter-rouge">docker kill</code> kills the container</li> <li>Docker daemon restarts which kills all running containers</li> </ul> <h4 id="status">status</h4> <p>The <code class="language-plaintext highlighter-rouge">status</code> filter matches containers by status. You can filter using <code class="language-plaintext highlighter-rouge">created</code>, <code class="language-plaintext highlighter-rouge">restarting</code>, <code class="language-plaintext highlighter-rouge">running</code>, <code class="language-plaintext highlighter-rouge">removing</code>, <code class="language-plaintext highlighter-rouge">paused</code>, <code class="language-plaintext highlighter-rouge">exited</code> and <code class="language-plaintext highlighter-rouge">dead</code>. For example, to filter for <code class="language-plaintext highlighter-rouge">running</code> containers:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker ps --filter status=running + +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +715ebfcee040 busybox "top" 16 minutes ago Up 16 minutes i_am_nostalgic +d5c976d3c462 busybox "top" 23 minutes ago Up 23 minutes top +9b6247364a03 busybox "top" 24 minutes ago Up 24 minutes nostalgic_stallman +</pre></div> <p>To filter for <code class="language-plaintext highlighter-rouge">paused</code> containers:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker ps --filter status=paused + +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +673394ef1d4c busybox "top" About an hour ago Up About an hour (Paused) nostalgic_shockley +</pre></div> <h4 id="ancestor">ancestor</h4> <p>The <code class="language-plaintext highlighter-rouge">ancestor</code> filter matches containers based on its image or a descendant of it. The filter supports the following image representation:</p> <ul> <li><code class="language-plaintext highlighter-rouge">image</code></li> <li><code class="language-plaintext highlighter-rouge">image:tag</code></li> <li><code class="language-plaintext highlighter-rouge">image:tag@digest</code></li> <li><code class="language-plaintext highlighter-rouge">short-id</code></li> <li><code class="language-plaintext highlighter-rouge">full-id</code></li> </ul> <p>If you don’t specify a <code class="language-plaintext highlighter-rouge">tag</code>, the <code class="language-plaintext highlighter-rouge">latest</code> tag is used. For example, to filter for containers that use the latest <code class="language-plaintext highlighter-rouge">ubuntu</code> image:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker ps --filter ancestor=ubuntu + +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +919e1179bdb8 ubuntu-c1 "top" About a minute ago Up About a minute admiring_lovelace +5d1e4a540723 ubuntu-c2 "top" About a minute ago Up About a minute admiring_sammet +82a598284012 ubuntu "top" 3 minutes ago Up 3 minutes sleepy_bose +bab2a34ba363 ubuntu "top" 3 minutes ago Up 3 minutes focused_yonath +</pre></div> <p>Match containers based on the <code class="language-plaintext highlighter-rouge">ubuntu-c1</code> image which, in this case, is a child of <code class="language-plaintext highlighter-rouge">ubuntu</code>:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker ps --filter ancestor=ubuntu-c1 + +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +919e1179bdb8 ubuntu-c1 "top" About a minute ago Up About a minute admiring_lovelace +</pre></div> <p>Match containers based on the <code class="language-plaintext highlighter-rouge">ubuntu</code> version <code class="language-plaintext highlighter-rouge">12.04.5</code> image:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker ps --filter ancestor=ubuntu:12.04.5 + +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +82a598284012 ubuntu:12.04.5 "top" 3 minutes ago Up 3 minutes sleepy_bose +</pre></div> <p>The following matches containers based on the layer <code class="language-plaintext highlighter-rouge">d0e008c6cf02</code> or an image that have this layer in its layer stack.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker ps --filter ancestor=d0e008c6cf02 + +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +82a598284012 ubuntu:12.04.5 "top" 3 minutes ago Up 3 minutes sleepy_bose +</pre></div> <h4 id="create-time">Create time</h4> <h5 id="before">before</h5> <p>The <code class="language-plaintext highlighter-rouge">before</code> filter shows only containers created before the container with given id or name. For example, having these containers created:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker ps + +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +9c3527ed70ce busybox "top" 14 seconds ago Up 15 seconds desperate_dubinsky +4aace5031105 busybox "top" 48 seconds ago Up 49 seconds focused_hamilton +6e63f6ff38b0 busybox "top" About a minute ago Up About a minute distracted_fermat +</pre></div> <p>Filtering with <code class="language-plaintext highlighter-rouge">before</code> would give:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker ps -f before=9c3527ed70ce + +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +4aace5031105 busybox "top" About a minute ago Up About a minute focused_hamilton +6e63f6ff38b0 busybox "top" About a minute ago Up About a minute distracted_fermat +</pre></div> <h5 id="since">since</h5> <p>The <code class="language-plaintext highlighter-rouge">since</code> filter shows only containers created since the container with given id or name. For example, with the same containers as in <code class="language-plaintext highlighter-rouge">before</code> filter:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker ps -f since=6e63f6ff38b0 + +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +9c3527ed70ce busybox "top" 10 minutes ago Up 10 minutes desperate_dubinsky +4aace5031105 busybox "top" 10 minutes ago Up 10 minutes focused_hamilton +</pre></div> <h4 id="volume">volume</h4> <p>The <code class="language-plaintext highlighter-rouge">volume</code> filter shows only containers that mount a specific volume or have a volume mounted in a specific path:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker ps --filter volume=remote-volume --format "table {{.ID}}\t{{.Mounts}}" + +CONTAINER ID MOUNTS +9c3527ed70ce remote-volume + +$ docker ps --filter volume=/data --format "table {{.ID}}\t{{.Mounts}}" + +CONTAINER ID MOUNTS +9c3527ed70ce remote-volume +</pre></div> <h4 id="network">network</h4> <p>The <code class="language-plaintext highlighter-rouge">network</code> filter shows only containers that are connected to a network with a given name or id.</p> <p>The following filter matches all containers that are connected to a network with a name containing <code class="language-plaintext highlighter-rouge">net1</code>.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -d --net=net1 --name=test1 ubuntu top +$ docker run -d --net=net2 --name=test2 ubuntu top + +$ docker ps --filter network=net1 + +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +9d4893ed80fe ubuntu "top" 10 minutes ago Up 10 minutes test1 +</pre></div> <p>The network filter matches on both the network’s name and id. The following example shows all containers that are attached to the <code class="language-plaintext highlighter-rouge">net1</code> network, using the network id as a filter;</p> <div class="highlight"><pre class="highlight" data-language="">$ docker network inspect --format "{{.ID}}" net1 + +8c0b4110ae930dbe26b258de9bc34a03f98056ed6f27f991d32919bfe401d7c5 + +$ docker ps --filter network=8c0b4110ae930dbe26b258de9bc34a03f98056ed6f27f991d32919bfe401d7c5 + +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +9d4893ed80fe ubuntu "top" 10 minutes ago Up 10 minutes test1 +</pre></div> <h4 id="publish-and-expose">publish and expose</h4> <p>The <code class="language-plaintext highlighter-rouge">publish</code> and <code class="language-plaintext highlighter-rouge">expose</code> filters show only containers that have published or exposed port with a given port number, port range, and/or protocol. The default protocol is <code class="language-plaintext highlighter-rouge">tcp</code> when not specified.</p> <p>The following filter matches all containers that have published port of 80:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -d --publish=80 busybox top +$ docker run -d --expose=8080 busybox top + +$ docker ps -a + +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +9833437217a5 busybox "top" 5 seconds ago Up 4 seconds 8080/tcp dreamy_mccarthy +fc7e477723b7 busybox "top" 50 seconds ago Up 50 seconds 0.0.0.0:32768->80/tcp admiring_roentgen + +$ docker ps --filter publish=80 + +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +fc7e477723b7 busybox "top" About a minute ago Up About a minute 0.0.0.0:32768->80/tcp admiring_roentgen +</pre></div> <p>The following filter matches all containers that have exposed TCP port in the range of <code class="language-plaintext highlighter-rouge">8000-8080</code>:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker ps --filter expose=8000-8080/tcp + +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +9833437217a5 busybox "top" 21 seconds ago Up 19 seconds 8080/tcp dreamy_mccarthy +</pre></div> <p>The following filter matches all containers that have exposed UDP port <code class="language-plaintext highlighter-rouge">80</code>:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker ps --filter publish=80/udp + +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +</pre></div> <h3 id="formatting">Formatting</h3> <p>The formatting option (<code class="language-plaintext highlighter-rouge">--format</code>) pretty-prints container output using a Go template.</p> <p>Valid placeholders for the Go template are listed below:</p> <table> <thead> <tr> <th style="text-align: left">Placeholder</th> <th style="text-align: left">Description</th> </tr> </thead> <tbody> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">.ID</code></td> <td style="text-align: left">Container ID</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">.Image</code></td> <td style="text-align: left">Image ID</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">.Command</code></td> <td style="text-align: left">Quoted command</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">.CreatedAt</code></td> <td style="text-align: left">Time when the container was created.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">.RunningFor</code></td> <td style="text-align: left">Elapsed time since the container was started.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">.Ports</code></td> <td style="text-align: left">Exposed ports.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">.State</code></td> <td style="text-align: left">Container status (for example; “created”, “running”, “exited”).</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">.Status</code></td> <td style="text-align: left">Container status with details about duration and health-status.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">.Size</code></td> <td style="text-align: left">Container disk size.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">.Names</code></td> <td style="text-align: left">Container names.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">.Labels</code></td> <td style="text-align: left">All labels assigned to the container.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">.Label</code></td> <td style="text-align: left">Value of a specific label for this container. For example <code class="language-plaintext highlighter-rouge">'{{.Label "com.docker.swarm.cpu"}}'</code> +</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">.Mounts</code></td> <td style="text-align: left">Names of the volumes mounted in this container.</td> </tr> <tr> <td style="text-align: left"><code class="language-plaintext highlighter-rouge">.Networks</code></td> <td style="text-align: left">Names of the networks attached to this container.</td> </tr> </tbody> </table> <p>When using the <code class="language-plaintext highlighter-rouge">--format</code> option, the <code class="language-plaintext highlighter-rouge">ps</code> command will either output the data exactly as the template declares or, when using the <code class="language-plaintext highlighter-rouge">table</code> directive, includes column headers as well.</p> <p>The following example uses a template without headers and outputs the <code class="language-plaintext highlighter-rouge">ID</code> and <code class="language-plaintext highlighter-rouge">Command</code> entries separated by a colon (<code class="language-plaintext highlighter-rouge">:</code>) for all running containers:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker ps --format "{{.ID}}: {{.Command}}" + +a87ecb4f327c: /bin/sh -c #(nop) MA +01946d9d34d8: /bin/sh -c #(nop) MA +c1d3b0166030: /bin/sh -c yum -y up +41d50ecd2f57: /bin/sh -c #(nop) MA +</pre></div> <p>To list all running containers with their labels in a table format you can use:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker ps --format "table {{.ID}}\t{{.Labels}}" + +CONTAINER ID LABELS +a87ecb4f327c com.docker.swarm.node=ubuntu,com.docker.swarm.storage=ssd +01946d9d34d8 +c1d3b0166030 com.docker.swarm.node=debian,com.docker.swarm.cpu=6 +41d50ecd2f57 com.docker.swarm.node=fedora,com.docker.swarm.cpu=3,com.docker.swarm.storage=ssd +</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/ps/" class="_attribution-link">https://docs.docker.com/engine/reference/commandline/ps/</a> + </p> +</div> |
