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%2Fcreate%2Findex.html | |
new repository
Diffstat (limited to 'devdocs/docker/engine%2Freference%2Fcommandline%2Fcreate%2Findex.html')
| -rw-r--r-- | devdocs/docker/engine%2Freference%2Fcommandline%2Fcreate%2Findex.html | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/devdocs/docker/engine%2Freference%2Fcommandline%2Fcreate%2Findex.html b/devdocs/docker/engine%2Freference%2Fcommandline%2Fcreate%2Findex.html new file mode 100644 index 00000000..940850dd --- /dev/null +++ b/devdocs/docker/engine%2Freference%2Fcommandline%2Fcreate%2Findex.html @@ -0,0 +1,69 @@ +<h1>docker create</h1> <p><br></p> <p>Create a new container</p> <h2 id="usage">Usage</h2> <div class="highlight"><pre class="highlight" data-language="">$ docker create [OPTIONS] IMAGE [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 container create</code> (or shorthand: <code class="language-plaintext highlighter-rouge">docker create</code>) command creates a new container from the specified image, without starting it.</p> <p>When creating a container, the docker daemon creates a writeable container layer over the specified image and prepares it for running the specified command. The container ID is then printed to <code class="language-plaintext highlighter-rouge">STDOUT</code>. This is similar to <code class="language-plaintext highlighter-rouge">docker run -d</code> except the container is never started. You can then use the <code class="language-plaintext highlighter-rouge">docker container start</code> (or shorthand: <code class="language-plaintext highlighter-rouge">docker start</code>) command to start the container at any point.</p> <p>This is useful when you want to set up a container configuration ahead of time so that it is ready to start when you need it. The initial status of the new container is <code class="language-plaintext highlighter-rouge">created</code>.</p> <p>The <code class="language-plaintext highlighter-rouge">docker create</code> command shares most of its options with the <code class="language-plaintext highlighter-rouge">docker run</code> command (which performs a <code class="language-plaintext highlighter-rouge">docker create</code> before starting it). Refer to the <a href="../run/index"><code class="language-plaintext highlighter-rouge">docker run</code> command</a> section and the <a href="../../run/index">Docker run reference</a> for details on the available flags and options.</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">--add-host</code></td> <td></td> <td>Add a custom host-to-IP mapping (host:ip)</td> </tr> <tr> <td> +<code class="language-plaintext highlighter-rouge">--attach</code> , <code class="language-plaintext highlighter-rouge">-a</code> +</td> <td></td> <td>Attach to STDIN, STDOUT or STDERR</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--blkio-weight</code></td> <td></td> <td>Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--blkio-weight-device</code></td> <td></td> <td>Block IO weight (relative device weight)</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--cap-add</code></td> <td></td> <td>Add Linux capabilities</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--cap-drop</code></td> <td></td> <td>Drop Linux capabilities</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--cgroup-parent</code></td> <td></td> <td>Optional parent cgroup for the container</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--cgroupns</code></td> <td></td> <td> +<a href="https://docs.docker.com/engine/api/v1.41/" target="_blank" rel="noopener" class="_"><span class="badge badge-info" data-toggle="tooltip" title="Open the API reference (in a new window)">API 1.41+</span></a><br>Cgroup namespace to use (host|private) 'host': Run the container in the Docker host's cgroup namespace 'private': Run the container in its own private cgroup namespace '': Use the cgroup namespace as configured by the default-cgroupns-mode option on the daemon (default)</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--cidfile</code></td> <td></td> <td>Write the container ID to the file</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--cpu-count</code></td> <td></td> <td>CPU count (Windows only)</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--cpu-percent</code></td> <td></td> <td>CPU percent (Windows only)</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--cpu-period</code></td> <td></td> <td>Limit CPU CFS (Completely Fair Scheduler) period</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--cpu-quota</code></td> <td></td> <td>Limit CPU CFS (Completely Fair Scheduler) quota</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--cpu-rt-period</code></td> <td></td> <td>Limit CPU real-time period in microseconds</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--cpu-rt-runtime</code></td> <td></td> <td>Limit CPU real-time runtime in microseconds</td> </tr> <tr> <td> +<code class="language-plaintext highlighter-rouge">--cpu-shares</code> , <code class="language-plaintext highlighter-rouge">-c</code> +</td> <td></td> <td>CPU shares (relative weight)</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--cpus</code></td> <td></td> <td>Number of CPUs</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--cpuset-cpus</code></td> <td></td> <td>CPUs in which to allow execution (0-3, 0,1)</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--cpuset-mems</code></td> <td></td> <td>MEMs in which to allow execution (0-3, 0,1)</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--device</code></td> <td></td> <td>Add a host device to the container</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--device-cgroup-rule</code></td> <td></td> <td>Add a rule to the cgroup allowed devices list</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--device-read-bps</code></td> <td></td> <td>Limit read rate (bytes per second) from a device</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--device-read-iops</code></td> <td></td> <td>Limit read rate (IO per second) from a device</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--device-write-bps</code></td> <td></td> <td>Limit write rate (bytes per second) to a device</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--device-write-iops</code></td> <td></td> <td>Limit write rate (IO per second) to a device</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--disable-content-trust</code></td> <td><code class="language-plaintext highlighter-rouge">true</code></td> <td>Skip image verification</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--dns</code></td> <td></td> <td>Set custom DNS servers</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--dns-opt</code></td> <td></td> <td>Set DNS options</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--dns-option</code></td> <td></td> <td>Set DNS options</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--dns-search</code></td> <td></td> <td>Set custom DNS search domains</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--domainname</code></td> <td></td> <td>Container NIS domain name</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--entrypoint</code></td> <td></td> <td>Overwrite the default ENTRYPOINT of the image</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">--expose</code></td> <td></td> <td>Expose a port or a range of ports</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--gpus</code></td> <td></td> <td> +<a href="https://docs.docker.com/engine/api/v1.40/" target="_blank" rel="noopener" class="_"><span class="badge badge-info" data-toggle="tooltip" title="Open the API reference (in a new window)">API 1.40+</span></a><br>GPU devices to add to the container ('all' to pass all GPUs)</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--group-add</code></td> <td></td> <td>Add additional groups to join</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--health-cmd</code></td> <td></td> <td>Command to run to check health</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--health-interval</code></td> <td></td> <td>Time between running the check (ms|s|m|h) (default 0s)</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--health-retries</code></td> <td></td> <td>Consecutive failures needed to report unhealthy</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--health-start-period</code></td> <td></td> <td>Start period for the container to initialize before starting health-retries countdown (ms|s|m|h) (default 0s)</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--health-timeout</code></td> <td></td> <td>Maximum time to allow one check to run (ms|s|m|h) (default 0s)</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--help</code></td> <td></td> <td>Print usage</td> </tr> <tr> <td> +<code class="language-plaintext highlighter-rouge">--hostname</code> , <code class="language-plaintext highlighter-rouge">-h</code> +</td> <td></td> <td>Container host name</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--init</code></td> <td></td> <td>Run an init inside the container that forwards signals and reaps processes</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">--io-maxbandwidth</code></td> <td></td> <td>Maximum IO bandwidth limit for the system drive (Windows only)</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--io-maxiops</code></td> <td></td> <td>Maximum IOps limit for the system drive (Windows only)</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--ip</code></td> <td></td> <td>IPv4 address (e.g., 172.30.100.104)</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--ip6</code></td> <td></td> <td>IPv6 address (e.g., 2001:db8::33)</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--ipc</code></td> <td></td> <td>IPC mode to use</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--isolation</code></td> <td></td> <td>Container isolation technology</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--kernel-memory</code></td> <td></td> <td>Kernel memory limit</td> </tr> <tr> <td> +<code class="language-plaintext highlighter-rouge">--label</code> , <code class="language-plaintext highlighter-rouge">-l</code> +</td> <td></td> <td>Set meta data on a container</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--label-file</code></td> <td></td> <td>Read in a line delimited file of labels</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--link</code></td> <td></td> <td>Add link to another container</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--link-local-ip</code></td> <td></td> <td>Container IPv4/IPv6 link-local addresses</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--log-driver</code></td> <td></td> <td>Logging driver for the container</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--log-opt</code></td> <td></td> <td>Log driver options</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--mac-address</code></td> <td></td> <td>Container MAC address (e.g., 92:d0:c6:0a:29:33)</td> </tr> <tr> <td> +<code class="language-plaintext highlighter-rouge">--memory</code> , <code class="language-plaintext highlighter-rouge">-m</code> +</td> <td></td> <td>Memory limit</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--memory-reservation</code></td> <td></td> <td>Memory soft limit</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--memory-swap</code></td> <td></td> <td>Swap limit equal to memory plus swap: '-1' to enable unlimited swap</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--memory-swappiness</code></td> <td><code class="language-plaintext highlighter-rouge">-1</code></td> <td>Tune container memory swappiness (0 to 100)</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--mount</code></td> <td></td> <td>Attach a filesystem mount to the container</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--name</code></td> <td></td> <td>Assign a name to the container</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--net</code></td> <td></td> <td>Connect a container to a network</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--net-alias</code></td> <td></td> <td>Add network-scoped alias for the container</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--network</code></td> <td></td> <td>Connect a container to a network</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--network-alias</code></td> <td></td> <td>Add network-scoped alias for the container</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--no-healthcheck</code></td> <td></td> <td>Disable any container-specified HEALTHCHECK</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--oom-kill-disable</code></td> <td></td> <td>Disable OOM Killer</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--oom-score-adj</code></td> <td></td> <td>Tune host's OOM preferences (-1000 to 1000)</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--pid</code></td> <td></td> <td>PID namespace to use</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--pids-limit</code></td> <td></td> <td>Tune container pids limit (set -1 for unlimited)</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--platform</code></td> <td></td> <td>Set platform if server is multi-platform capable</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--privileged</code></td> <td></td> <td>Give extended privileges to this container</td> </tr> <tr> <td> +<code class="language-plaintext highlighter-rouge">--publish</code> , <code class="language-plaintext highlighter-rouge">-p</code> +</td> <td></td> <td>Publish a container's port(s) to the host</td> </tr> <tr> <td> +<code class="language-plaintext highlighter-rouge">--publish-all</code> , <code class="language-plaintext highlighter-rouge">-P</code> +</td> <td></td> <td>Publish all exposed ports to random ports</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--pull</code></td> <td><code class="language-plaintext highlighter-rouge">missing</code></td> <td>Pull image before creating ("always"|"missing"|"never")</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--read-only</code></td> <td></td> <td>Mount the container's root filesystem as read only</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--restart</code></td> <td><code class="language-plaintext highlighter-rouge">no</code></td> <td>Restart policy to apply when a container exits</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--rm</code></td> <td></td> <td>Automatically remove the container when it exits</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--runtime</code></td> <td></td> <td>Runtime to use for this container</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--security-opt</code></td> <td></td> <td>Security Options</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--shm-size</code></td> <td></td> <td>Size of /dev/shm</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--stop-signal</code></td> <td><code class="language-plaintext highlighter-rouge">SIGTERM</code></td> <td>Signal to stop a container</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--stop-timeout</code></td> <td></td> <td>Timeout (in seconds) to stop a container</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--storage-opt</code></td> <td></td> <td>Storage driver options for the container</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--sysctl</code></td> <td></td> <td>Sysctl options</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--tmpfs</code></td> <td></td> <td>Mount a tmpfs directory</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">--ulimit</code></td> <td></td> <td>Ulimit options</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">--userns</code></td> <td></td> <td>User namespace to use</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--uts</code></td> <td></td> <td>UTS namespace to use</td> </tr> <tr> <td> +<code class="language-plaintext highlighter-rouge">--volume</code> , <code class="language-plaintext highlighter-rouge">-v</code> +</td> <td></td> <td>Bind mount a volume</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--volume-driver</code></td> <td></td> <td>Optional volume driver for the container</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--volumes-from</code></td> <td></td> <td>Mount volumes from the specified container(s)</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="create-and-start-a-container">Create and start a container</h3> <p>The following example creates an interactive container with a pseudo-TTY attached, then starts the container and attaches to it:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker container create -i -t --name mycontainer alpine +6d8af538ec541dd581ebc2a24153a28329acb5268abe5ef868c1f1a261221752 + +$ docker container start --attach -i mycontainer +/ # echo hello world +hello world +</pre></div> <p>The above is the equivalent of a <code class="language-plaintext highlighter-rouge">docker run</code>:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -it --name mycontainer2 alpine +/ # echo hello world +hello world +</pre></div> <h3 id="initialize-volumes">Initialize volumes</h3> <p>Container volumes are initialized during the <code class="language-plaintext highlighter-rouge">docker create</code> phase (i.e., <code class="language-plaintext highlighter-rouge">docker run</code> too). For example, this allows you to <code class="language-plaintext highlighter-rouge">create</code> the <code class="language-plaintext highlighter-rouge">data</code> volume container, and then use it from another container:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker create -v /data --name data ubuntu + +240633dfbb98128fa77473d3d9018f6123b99c454b3251427ae190a7d951ad57 + +$ docker run --rm --volumes-from data ubuntu ls -la /data + +total 8 +drwxr-xr-x 2 root root 4096 Dec 5 04:10 . +drwxr-xr-x 48 root root 4096 Dec 5 04:11 .. +</pre></div> <p>Similarly, <code class="language-plaintext highlighter-rouge">create</code> a host directory bind mounted volume container, which can then be used from the subsequent container:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker create -v /home/docker:/docker --name docker ubuntu + +9aa88c08f319cd1e4515c3c46b0de7cc9aa75e878357b1e96f91e2c773029f03 + +$ docker run --rm --volumes-from docker ubuntu ls -la /docker + +total 20 +drwxr-sr-x 5 1000 staff 180 Dec 5 04:00 . +drwxr-xr-x 48 root root 4096 Dec 5 04:13 .. +-rw-rw-r-- 1 1000 staff 3833 Dec 5 04:01 .ash_history +-rw-r--r-- 1 1000 staff 446 Nov 28 11:51 .ashrc +-rw-r--r-- 1 1000 staff 25 Dec 5 04:00 .gitconfig +drwxr-sr-x 3 1000 staff 60 Dec 1 03:28 .local +-rw-r--r-- 1 1000 staff 920 Nov 28 11:51 .profile +drwx--S--- 2 1000 staff 460 Dec 5 00:51 .ssh +drwxr-xr-x 32 1000 staff 1140 Dec 5 04:01 docker +</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/create/" class="_attribution-link">https://docs.docker.com/engine/reference/commandline/create/</a> + </p> +</div> |
