docker-run (1) - Linux Manuals
docker-run: Run a command in a new container
NAME
docker-run - Run a command in a new container
SYNOPSIS
docker run [-a|--attach[=[]]] [--add-host[=[]]] [--blkio-weight[=[BLKIO-WEIGHT]]] [--blkio-weight-device[=[]]] [--cpu-shares[=0]] [--cap-add[=[]]] [--cap-drop[=[]]] [--cgroupns[=[]]] [--cgroup-parent[=CGROUP-PATH]] [--cidfile[=CIDFILE]] [--cpu-count[=0]] [--cpu-percent[=0]] [--cpu-period[=0]] [--cpu-quota[=0]] [--cpu-rt-period[=0]] [--cpu-rt-runtime[=0]] [--cpus[=0.0]] [--cpuset-cpus[=CPUSET-CPUS]] [--cpuset-mems[=CPUSET-MEMS]] [-d|--detach] [--detach-keys[=[]]] [--device[=[]]] [--device-cgroup-rule[=[]]] [--device-read-bps[=[]]] [--device-read-iops[=[]]] [--device-write-bps[=[]]] [--device-write-iops[=[]]] [--dns[=[]]] [--dns-option[=[]]] [--dns-search[=[]]] [--domainname[=DOMAINNAME]] [-e|--env[=[]]] [--entrypoint[=ENTRYPOINT]] [--env-file[=[]]] [--expose[=[]]] [--group-add[=[]]] [-h|--hostname[=HOSTNAME]] [--help] [--init] [-i|--interactive] [--ip[=IPv4-ADDRESS]] [--ip6[=IPv6-ADDRESS]] [--ipc[=IPC]] [--isolation[=default]] [--kernel-memory[=KERNEL-MEMORY]] [-l|--label[=[]]] [--label-file[=[]]] [--link[=[]]] [--link-local-ip[=[]]] [--log-driver[=[]]] [--log-opt[=[]]] [-m|--memory[=MEMORY]] [--mac-address[=MAC-ADDRESS]] [--memory-reservation[=MEMORY-RESERVATION]] [--memory-swap[=LIMIT]] [--memory-swappiness[=MEMORY-SWAPPINESS]] [--mount[=[MOUNT]]] [--name[=NAME]] [--network-alias[=[]]] [--network[="bridge"]] [--oom-kill-disable] [--oom-score-adj[=0]] [-P|--publish-all] [-p|--publish[=[]]] [--pid[=[PID]]] [--userns[=[]]] [--pids-limit[=PIDS_LIMIT]] [--privileged] [--read-only] [--restart[=RESTART]] [--rm] [--security-opt[=[]]] [--storage-opt[=[]]] [--stop-signal[=SIGNAL]] [--stop-timeout[=TIMEOUT]] [--shm-size[=[]]] [--sig-proxy[=true]] [--sysctl[=[]]] [-t|--tty] [--tmpfs[=[CONTAINER-DIR[:OPTIONS]]] [-u|--user[=USER]] [--ulimit[=[]]] [--uts[=[]]] [-v|--volume[=[[HOST-DIR:]CONTAINER-DIR[:OPTIONS]]]] [--volume-driver[=DRIVER]] [--volumes-from[=[]]] [-w|--workdir[=WORKDIR]] IMAGE [COMMAND] [ARG...]
DESCRIPTION
Run a process in a new container. docker run starts a process with its own file system, its own networking, and its own isolated process tree. The IMAGE which starts the process may define defaults related to the process that will be run in the container, the networking to expose, and more, but docker run gives final control to the operator or administrator who starts the container from the image. For that reason docker run has more options than any other Docker command.
If the IMAGE is not already loaded then docker run will pull the IMAGE, and all image dependencies, from the repository in the same way running docker pull IMAGE, before it starts the container from that image.
OPTIONS
-a, --attach=[]
In foreground mode (the default when -d
is not specified), docker run can start the process in the container
and attach the console to the process's standard input, output, and standard
error. It can even pretend to be a TTY (this is what most commandline
executables expect) and pass along signals. The -a option can be set for
each of stdin, stdout, and stderr.
--add-host=[]
Add a line to /etc/hosts. The format is hostname:ip. The --add-host
option can be set multiple times.
--blkio-weight=0
--blkio-weight-device=[]
--cpu-shares=0
By default, all containers get the same proportion of CPU cycles. This proportion
can be modified by changing the container's CPU share weighting relative
to the weighting of all other running containers.
To modify the proportion from the default of 1024, use the --cpu-shares
flag to set the weighting to 2 or higher.
The proportion will only apply when CPU-intensive processes are running.
When tasks in one container are idle, other containers can use the
left-over CPU time. The actual amount of CPU time will vary depending on
the number of containers running on the system.
For example, consider three containers, one has a cpu-share of 1024 and
two others have a cpu-share setting of 512. When processes in all three
containers attempt to use 100% of CPU, the first container would receive
50% of the total CPU time. If you add a fourth container with a cpu-share
of 1024, the first container only gets 33% of the CPU. The remaining containers
receive 16.5%, 16.5% and 33% of the CPU.
On a multi-core system, the shares of CPU time are distributed over all CPU
cores. Even if a container is limited to less than 100% of CPU time, it can
use 100% of each individual CPU core.
For example, consider a system with more than three cores. If you start one
container {C0} with -c=512 running one process, and another container
{C1} with -c=1024 running two processes, this can result in the following
division of CPU shares:
--cap-add=[]
--cap-drop=[]
--cgroupns=""
--cgroup-parent=""
--cidfile=""
--cpu-count=0
--cpu-percent=0
--cpu-period=0
Limit the container's CPU usage. This flag tell the kernel to restrict the container's CPU usage to the period you specify.
--cpuset-cpus=""
--cpuset-mems=""
If you have four memory nodes on your system (0-3), use --cpuset-mems=0,1
then processes in your Docker container will only use memory from the first
two memory nodes.
--cpu-quota=0
Limit the container's CPU usage. By default, containers run with the full
CPU resource. This flag tell the kernel to restrict the container's CPU usage
to the quota you specify.
--cpu-rt-period=0
Limit the container's Real Time CPU usage. This flag tell the kernel to restrict the container's Real Time CPU usage to the period you specify.
--cpu-rt-runtime=0
Limit the containers Real Time CPU usage. This flag tells the kernel to limit the amount of time in a given CPU period Real Time tasks may consume. Ex:
The sum of all runtimes across containers cannot exceed the amount allotted to the parent cgroup.
--cpus=0.0
-d, --detach=true|false
At any time you can run docker ps in
the other shell to view a list of the running containers. You can reattach to a
detached container with docker attach.
When attached in the tty mode, you can detach from the container (and leave it
running) using a configurable key sequence. The default sequence is CTRL-p CTRL-q.
You configure the key sequence using the --detach-keys option or a configuration file.
See config-json(5) for documentation on using a configuration file.
--detach-keys=key
--device=onhost:incontainer[:mode]
For example, --device=/dev/sdc:/dev/xvdc:rwm will give a container all
permissions for the host device /dev/sdc, seen as /dev/xvdc inside the container.
--device-cgroup-rule="type major:minor mode"
Example: --device-cgroup-rule "c 1:3 mr": allow for a character device idendified by 1:3 to be created and read.
--device-read-bps=[]
--device-read-iops=[]
--device-write-bps=[]
--device-write-iops=[]
--dns-search=[]
--dns-option=[]
--dns=[]
This option can be used to override the DNS
configuration passed to the container. Typically this is necessary when the
host DNS configuration is invalid for the container (e.g., 127.0.0.1). When this
is the case the --dns flags is necessary for every run.
--domainname=""
Sets the container's NIS domain name (see also setdomainname(2)) that is
-e, --env=[]
This option allows you to specify arbitrary
environment variables that are available for the process that will be launched
inside of the container.
--entrypoint=""
This option allows you to overwrite the default entrypoint of the image that
is set in the Dockerfile. The ENTRYPOINT of an image is similar to a COMMAND
because it specifies what executable to run when the container starts, but it is
(purposely) more difficult to override. The ENTRYPOINT gives a container its
default nature or behavior, so that when you set an ENTRYPOINT you can run the
container as if it were that binary, complete with default options, and you can
pass in more options via the COMMAND. But, sometimes an operator may want to run
something else inside the container, so you can override the default ENTRYPOINT
at runtime by using a --entrypoint and a string to specify the new
ENTRYPOINT.
--env-file=[]
--expose=[]
--group-add=[]
-h, --hostname=""
Sets the container host name that is available inside the container.
--help
--init
-i, --interactive=true|false
When set to true, keep stdin open even if not attached.
--ip=""
It can only be used in conjunction with --network for user-defined networks
--ip6=""
It can only be used in conjunction with --network for user-defined networks
--ipc=""
If not specified, daemon default is used, which can either be private
or shareable, depending on the daemon version and configuration.
--isolation="default"
-l, --label key=value
--kernel-memory=number[S]
Constrains the kernel memory available to a container. If a limit of 0
is specified (not using --kernel-memory), the container's kernel memory
is not limited. If you specify a limit, it may be rounded up to a multiple
of the operating system's page size and the value can be very large,
millions of trillions.
--label-file=[]
--link=name-or-id[:alias]
If the operator
uses --link when starting the new client container, then the client
container can access the exposed port via a private networking interface. Docker
will set some environment variables in the client container to help indicate
which interface and port to use.
--link-local-ip=[]
--log-driver="json-file|syslog|journald|gelf|fluentd|awslogs|splunk|etwlogs|gcplogs|none"
--log-opt=[]
-m, --memory=number[*S]
Allows you to constrain the memory available to a container. If the host
supports swap memory, then the -m memory setting can be larger than physical
RAM. If a limit of 0 is specified (not using -m), the container's memory is
not limited. The actual limit may be rounded up to a multiple of the operating
system's page size (the value would be very large, that's millions of trillions).
--memory-reservation=number[*S]
After setting memory reservation, when the system detects memory contention
or low memory, containers are forced to restrict their consumption to their
reservation. So you should always set the value below --memory, otherwise the
hard limit will take precedence. By default, memory reservation will be the same
as memory limit.
--memory-swap=number[S]
This option can only be used together with --memory. The argument should always be larger than that of --memory. Default is double the value of --memory. Set to -1 to enable unlimited swap.
--mac-address=""
Remember that the MAC address in an Ethernet network must be unique.
The IPv6 link-local address will be based on the device's MAC address
according to RFC4862.
--mount type=TYPE,TYPE-SPECIFIC-OPTION[,...]
Current supported mount TYPES are bind, volume, and tmpfs.
e.g.
type=bind,source=/path/on/host,destination=/path/in/container
type=volume,source=my-volume,destination=/path/in/container,volume-label="color=red",volume-label="shape=round"
type=tmpfs,tmpfs-size=512M,destination=/path/in/container
Common Options:
Note: setting readonly for a bind mount does not make its submounts
Options specific to bind:
Options specific to volume:
Options specific to tmpfs:
--name=""
The operator can identify a container in three ways:
The UUID identifiers come from the Docker daemon, and if a name is not assigned
to the container with --name then the daemon will also generate a random
string name. The name is useful when defining links (see --link) (or any
other place you need to identify a container). This works for both background
and foreground Docker containers.
--network=type
Default is bridge.
--network-alias=[]
--oom-kill-disable=true|false
--oom-score-adj=""
-P, --publish-all=true|false
When set to true publish all exposed ports to the host interfaces. The
default is false. If the operator uses -P (or -p) then Docker will make the
exposed port accessible on the host and the ports will be available to any
client that can reach the host. When using -P, Docker will bind any exposed
port to a random port on the host within an ephemeral port range defined by
/proc/sys/net/ipv4/ip_local_port_range. To find the mapping between the host
ports and the exposed ports, use docker port(1).
-p, --publish ip:[hostPort]:containerPort | [hostPort:]containerPort
Both hostPort and containerPort can be specified as a range.
When specifying ranges for both, the number of ports in ranges should be equal.
Examples: -p 1234-1236:1222-1224, -p 127.0.0.1:$HOSTPORT:$CONTAINERPORT.
Use docker port(1) to see the actual mapping, e.g. docker port CONTAINER $CONTAINERPORT.
--pid=""
PID container CPU CPU share
100 {C0} 0 100% of CPU0
101 {C1} 1 100% of CPU1
102 {C1} 2 100% of CPU2
On Windows Server containers, this is approximated as a percentage of total CPU usage.
On Windows Server containers, the processor resource controls are mutually exclusive, the order of precedence is CPUCount first, then CPUShares, and CPUPercent last.
On Windows Server containers, the processor resource controls are mutually exclusive, the order of precedence is CPUCount first, then CPUShares, and CPUPercent last.
Value Description (empty) Use daemon's default. none
Own private IPC namespace, with /dev/shm not mounted.
private Own private IPC namespace. shareable
Own private IPC namespace, with a possibility to share it with other containers.
container:name-or-ID
Join another ("shareable") container's IPC namespace.
host
Use the host system's IPC namespace.
Identifier type Example value UUID long identifier
"f78375b1c487e03c9438c729345e54db9d20cfa2ac1fc3494b6eb60872e74778"
UUID short identifier "f78375b1c487" Name "evil_ptolemy"
Value Description none
No networking in the container.
bridge
Connect the container to the default Docker bridge via veth interfaces.
host
Use the host's network stack inside the container.
container:name|id
Use the network stack of another container, specified via its name or id.
network-name|network-id
Connects the container to a user created network (using docker network create command)