.nh
.TH "DOCKER" "1" "May 2024" "Docker Community" "Docker User Manuals"

.SH NAME
.PP
docker-container-create - Create a new container


.SH SYNOPSIS
.PP
\fBdocker container create [OPTIONS] IMAGE [COMMAND] [ARG...]\fP


.SH DESCRIPTION
.PP
Creates a writeable container layer over the specified image and prepares it for
running the specified command. The container ID is then printed to STDOUT. This
is similar to \fBdocker run -d\fP except the container is never started. You can
then use the \fBdocker start \fP command to start the container at
any point.

.PP
The initial status of the container created with \fBdocker create\fP is 'created'.

.SS OPTIONS
.PP
The \fBCONTAINER-DIR\fR must be an absolute path such as \fB/src/docs\fR\&. The \fBHOST-DIR\fR
can be an absolute path or a \fBname\fR value. A \fBname\fR value must start with an
alphanumeric character, followed by \fBa-z0-9\fR, \fB_\fR (underscore), \fB\&.\fR (period) or
\fB-\fR (hyphen). An absolute path starts with a \fB/\fR (forward slash).

.PP
If you supply a \fBHOST-DIR\fR that is an absolute path,  Docker bind-mounts to the
path you specify. If you supply a \fBname\fR, Docker creates a named volume by that
\fBname\fR\&. For example, you can specify either \fB/foo\fR or \fBfoo\fR for a \fBHOST-DIR\fR
value. If you supply the \fB/foo\fR value, Docker creates a bind mount. If you
supply the \fBfoo\fR specification, Docker creates a named volume.

.PP
You can specify multiple  \fB-v\fP options to mount one or more mounts to a
container. To use these same mounts in other containers, specify the
\fB--volumes-from\fP option also.

.PP
You can supply additional options for each bind mount following an additional
colon.  A \fB:ro\fR or \fB:rw\fR suffix mounts a volume in read-only or read-write
mode, respectively. By default, volumes are mounted in read-write mode.
.br
You can also specify the consistency requirement for the mount, either
\fB:consistent\fR (the default), \fB:cached\fR, or \fB:delegated\fR\&.  Multiple options are
separated by commas, e.g. \fB:ro,cached\fR\&.

.PP
Labeling systems like SELinux require that proper labels are placed on volume
content mounted into a container. Without a label, the security system might
prevent the processes running inside the container from using the content. By
default, Docker does not change the labels set by the OS.

.PP
To change a label in the container context, you can add either of two suffixes
\fB:z\fR or \fB:Z\fR to the volume mount. These suffixes tell Docker to relabel file
objects on the shared volumes. The \fBz\fR option tells Docker that two containers
share the volume content. As a result, Docker labels the content with a shared
content label. Shared volume labels allow all containers to read/write content.
The \fBZ\fR option tells Docker to label the content with a private unshared label.
Only the current container can use a private volume.

.PP
By default bind mounted volumes are \fBprivate\fR\&. That means any mounts done
inside container will not be visible on host and vice-a-versa. One can change
this behavior by specifying a volume mount propagation property. Making a
volume \fBshared\fR mounts done under that volume inside container will be
visible on host and vice-a-versa. Making a volume \fBslave\fR enables only one
way mount propagation and that is mounts done on host under that volume
will be visible inside container but not the other way around.

.PP
To control mount propagation property of volume one can use \fB:[r]shared\fR,
\fB:[r]slave\fR or \fB:[r]private\fR propagation flag. Propagation property can
be specified only for bind mounted volumes and not for internal volumes or
named volumes. For mount propagation to work source mount point (mount point
where source dir is mounted on) has to have right propagation properties. For
shared volumes, source mount point has to be shared. And for slave volumes,
source mount has to be either shared or slave.

.PP
Use \fBdf <source-dir>\fR to figure out the source mount and then use
\fBfindmnt -o TARGET,PROPAGATION <source-mount-dir>\fR to figure out propagation
properties of source mount. If \fBfindmnt\fR utility is not available, then one
can look at mount entry for source mount point in \fB/proc/self/mountinfo\fR\&. Look
at \fBoptional fields\fR and see if any propagation properties are specified.
\fBshared:X\fR means mount is \fBshared\fR, \fBmaster:X\fR means mount is \fBslave\fR and if
nothing is there that means mount is \fBprivate\fR\&.

.PP
To change propagation properties of a mount point use \fBmount\fR command. For
example, if one wants to bind mount source directory \fB/foo\fR one can do
\fBmount --bind /foo /foo\fR and \fBmount --make-private --make-shared /foo\fR\&. This
will convert /foo into a \fBshared\fR mount point. Alternatively one can directly
change propagation properties of source mount. Say \fB/\fR is source mount for
\fB/foo\fR, then use \fBmount --make-shared /\fR to convert \fB/\fR into a \fBshared\fR mount.

.PP
.RS

.PP
\fBNote\fP:
When using systemd to manage the Docker daemon's start and stop, in the systemd
unit file there is an option to control mount propagation for the Docker daemon
itself, called \fBMountFlags\fR\&. The value of this setting may cause Docker to not
see mount propagation changes made on the mount point. For example, if this value
is \fBslave\fR, you may not be able to use the \fBshared\fR or \fBrshared\fR propagation on
a volume.

.RE

.PP
To disable automatic copying of data from the container path to the volume, use
the \fBnocopy\fR flag. The \fBnocopy\fR flag can be set on named volumes, and does not
apply to bind mounts..


.SH OPTIONS
.PP
\fB--add-host\fP=
	Add a custom host-to-IP mapping (host:ip)

.PP
\fB--annotation\fP=map[]
	Add an annotation to the container (passed through to the OCI runtime)

.PP
\fB-a\fP, \fB--attach\fP=
	Attach to STDIN, STDOUT or STDERR

.PP
\fB--blkio-weight\fP=0
	Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)

.PP
\fB--blkio-weight-device\fP=[]
	Block IO weight (relative device weight)

.PP
\fB--cap-add\fP=
	Add Linux capabilities

.PP
\fB--cap-drop\fP=
	Drop Linux capabilities

.PP
\fB--cgroup-parent\fP=""
	Optional parent cgroup for the container

.PP
\fB--cgroupns\fP=""
	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)

.PP
\fB--cidfile\fP=""
	Write the container ID to the file

.PP
\fB--cpu-count\fP=0
	CPU count (Windows only)

.PP
\fB--cpu-percent\fP=0
	CPU percent (Windows only)

.PP
\fB--cpu-period\fP=0
	Limit CPU CFS (Completely Fair Scheduler) period

.PP
\fB--cpu-quota\fP=0
	Limit CPU CFS (Completely Fair Scheduler) quota

.PP
\fB--cpu-rt-period\fP=0
	Limit CPU real-time period in microseconds

.PP
\fB--cpu-rt-runtime\fP=0
	Limit CPU real-time runtime in microseconds

.PP
\fB-c\fP, \fB--cpu-shares\fP=0
	CPU shares (relative weight)

.PP
\fB--cpus\fP=
	Number of CPUs

.PP
\fB--cpuset-cpus\fP=""
	CPUs in which to allow execution (0-3, 0,1)

.PP
\fB--cpuset-mems\fP=""
	MEMs in which to allow execution (0-3, 0,1)

.PP
\fB--device\fP=
	Add a host device to the container

.PP
\fB--device-cgroup-rule\fP=
	Add a rule to the cgroup allowed devices list

.PP
\fB--device-read-bps\fP=[]
	Limit read rate (bytes per second) from a device

.PP
\fB--device-read-iops\fP=[]
	Limit read rate (IO per second) from a device

.PP
\fB--device-write-bps\fP=[]
	Limit write rate (bytes per second) to a device

.PP
\fB--device-write-iops\fP=[]
	Limit write rate (IO per second) to a device

.PP
\fB--disable-content-trust\fP[=true]
	Skip image verification

.PP
\fB--dns\fP=
	Set custom DNS servers

.PP
\fB--dns-option\fP=
	Set DNS options

.PP
\fB--dns-search\fP=
	Set custom DNS search domains

.PP
\fB--domainname\fP=""
	Container NIS domain name

.PP
\fB--entrypoint\fP=""
	Overwrite the default ENTRYPOINT of the image

.PP
\fB-e\fP, \fB--env\fP=
	Set environment variables

.PP
\fB--env-file\fP=
	Read in a file of environment variables

.PP
\fB--expose\fP=
	Expose a port or a range of ports

.PP
\fB--gpus\fP=
	GPU devices to add to the container ('all' to pass all GPUs)

.PP
\fB--group-add\fP=
	Add additional groups to join

.PP
\fB--health-cmd\fP=""
	Command to run to check health

.PP
\fB--health-interval\fP=0s
	Time between running the check (ms|s|m|h) (default 0s)

.PP
\fB--health-retries\fP=0
	Consecutive failures needed to report unhealthy

.PP
\fB--health-start-interval\fP=0s
	Time between running the check during the start period (ms|s|m|h) (default 0s)

.PP
\fB--health-start-period\fP=0s
	Start period for the container to initialize before starting health-retries countdown (ms|s|m|h) (default 0s)

.PP
\fB--health-timeout\fP=0s
	Maximum time to allow one check to run (ms|s|m|h) (default 0s)

.PP
\fB--help\fP[=false]
	Print usage

.PP
\fB-h\fP, \fB--hostname\fP=""
	Container host name

.PP
\fB--init\fP[=false]
	Run an init inside the container that forwards signals and reaps processes

.PP
\fB-i\fP, \fB--interactive\fP[=false]
	Keep STDIN open even if not attached

.PP
\fB--io-maxbandwidth\fP=0
	Maximum IO bandwidth limit for the system drive (Windows only)

.PP
\fB--io-maxiops\fP=0
	Maximum IOps limit for the system drive (Windows only)

.PP
\fB--ip\fP=""
	IPv4 address (e.g., 172.30.100.104)

.PP
\fB--ip6\fP=""
	IPv6 address (e.g., 2001:db8::33)

.PP
\fB--ipc\fP=""
	IPC mode to use

.PP
\fB--isolation\fP=""
	Container isolation technology

.PP
\fB--kernel-memory\fP=0
	Kernel memory limit

.PP
\fB-l\fP, \fB--label\fP=
	Set meta data on a container

.PP
\fB--label-file\fP=
	Read in a line delimited file of labels

.PP
\fB--link\fP=
	Add link to another container

.PP
\fB--link-local-ip\fP=
	Container IPv4/IPv6 link-local addresses

.PP
\fB--log-driver\fP=""
	Logging driver for the container

.PP
\fB--log-opt\fP=
	Log driver options

.PP
\fB--mac-address\fP=""
	Container MAC address (e.g., 92:d0:c6:0a:29:33)

.PP
\fB-m\fP, \fB--memory\fP=0
	Memory limit

.PP
\fB--memory-reservation\fP=0
	Memory soft limit

.PP
\fB--memory-swap\fP=0
	Swap limit equal to memory plus swap: '-1' to enable unlimited swap

.PP
\fB--memory-swappiness\fP=-1
	Tune container memory swappiness (0 to 100)

.PP
\fB--mount\fP=
	Attach a filesystem mount to the container

.PP
\fB--name\fP=""
	Assign a name to the container

.PP
\fB--network\fP=
	Connect a container to a network

.PP
\fB--network-alias\fP=
	Add network-scoped alias for the container

.PP
\fB--no-healthcheck\fP[=false]
	Disable any container-specified HEALTHCHECK

.PP
\fB--oom-kill-disable\fP[=false]
	Disable OOM Killer

.PP
\fB--oom-score-adj\fP=0
	Tune host's OOM preferences (-1000 to 1000)

.PP
\fB--pid\fP=""
	PID namespace to use

.PP
\fB--pids-limit\fP=0
	Tune container pids limit (set -1 for unlimited)

.PP
\fB--platform\fP=""
	Set platform if server is multi-platform capable

.PP
\fB--privileged\fP[=false]
	Give extended privileges to this container

.PP
\fB-p\fP, \fB--publish\fP=
	Publish a container's port(s) to the host

.PP
\fB-P\fP, \fB--publish-all\fP[=false]
	Publish all exposed ports to random ports

.PP
\fB--pull\fP="missing"
	Pull image before creating ("always", "|missing", "never")

.PP
\fB-q\fP, \fB--quiet\fP[=false]
	Suppress the pull output

.PP
\fB--read-only\fP[=false]
	Mount the container's root filesystem as read only

.PP
\fB--restart\fP="no"
	Restart policy to apply when a container exits

.PP
\fB--rm\fP[=false]
	Automatically remove the container when it exits

.PP
\fB--runtime\fP=""
	Runtime to use for this container

.PP
\fB--security-opt\fP=
	Security Options

.PP
\fB--shm-size\fP=0
	Size of /dev/shm

.PP
\fB--stop-signal\fP=""
	Signal to stop the container

.PP
\fB--stop-timeout\fP=0
	Timeout (in seconds) to stop a container

.PP
\fB--storage-opt\fP=
	Storage driver options for the container

.PP
\fB--sysctl\fP=map[]
	Sysctl options

.PP
\fB--tmpfs\fP=
	Mount a tmpfs directory

.PP
\fB-t\fP, \fB--tty\fP[=false]
	Allocate a pseudo-TTY

.PP
\fB--ulimit\fP=[]
	Ulimit options

.PP
\fB-u\fP, \fB--user\fP=""
	Username or UID (format: [:])

.PP
\fB--userns\fP=""
	User namespace to use

.PP
\fB--uts\fP=""
	UTS namespace to use

.PP
\fB-v\fP, \fB--volume\fP=
	Bind mount a volume

.PP
\fB--volume-driver\fP=""
	Optional volume driver for the container

.PP
\fB--volumes-from\fP=
	Mount volumes from the specified container(s)

.PP
\fB-w\fP, \fB--workdir\fP=""
	Working directory inside the container


.SH EXAMPLE
.EX
### Specify isolation technology for container (--isolation)

This option is useful in situations where you are running Docker containers on
Windows. The `--isolation=<value>` option sets a container's isolation
technology. On Linux, the only supported is the `default` option which uses
Linux namespaces. On Microsoft Windows, you can specify these values:

* `default`: Use the value specified by the Docker daemon's `--exec-opt` . If the `daemon` does not specify an isolation technology, Microsoft Windows uses `process` as its default value.
* `process`: Namespace isolation only.
* `hyperv`: Hyper-V hypervisor partition-based isolation.

Specifying the `--isolation` flag without a value is the same as setting `--isolation="default"`.

### Dealing with dynamically created devices (--device-cgroup-rule)

Devices available to a container are assigned at creation time. The
assigned devices will both be added to the cgroup.allow file and
created into the container once it is run. This poses a problem when
a new device needs to be added to running container.

One of the solution is to add a more permissive rule to a container
allowing it access to a wider range of devices. For example, supposing
our container needs access to a character device with major `42` and
any number of minor number (added as new devices appear), the
following rule would be added:

```console
$ docker create --device-cgroup-rule='c 42:* rmw' --name my-container my-image

.EE

.PP
Then, a user could ask \fBudev\fR to execute a script that would \fBdocker exec my-container mknod newDevX c 42 <minor>\fR
the required device when it is added.

.PP
NOTE: initially present devices still need to be explicitly added to
the create/run command

.PP
```


.SH SEE ALSO
.PP
\fBdocker-container(1)\fP
