2013-05-21 11:47:16 -06:00
|
|
|
:title: Run Command
|
|
|
|
:description: Run a command in a new container
|
|
|
|
:keywords: run, container, docker, documentation
|
|
|
|
|
2013-04-02 04:52:44 +03:00
|
|
|
===========================================
|
|
|
|
``run`` -- Run a command in a new container
|
|
|
|
===========================================
|
|
|
|
|
|
|
|
::
|
|
|
|
|
2013-08-07 13:57:31 +02:00
|
|
|
Usage: docker run [OPTIONS] IMAGE[:TAG] [COMMAND] [ARG...]
|
2013-04-02 04:52:44 +03:00
|
|
|
|
|
|
|
Run a command in a new container
|
|
|
|
|
|
|
|
-a=map[]: Attach to stdin, stdout or stderr.
|
2013-05-07 11:43:45 -07:00
|
|
|
-c=0: CPU shares (relative weight)
|
2013-07-11 23:38:43 +03:00
|
|
|
-cidfile="": Write the container ID to the file
|
2013-07-29 14:17:15 -07:00
|
|
|
-d=false: Detached mode: Run container in the background, print new container id
|
2013-04-02 04:52:44 +03:00
|
|
|
-e=[]: Set environment variables
|
|
|
|
-h="": Container host name
|
|
|
|
-i=false: Keep stdin open even if not attached
|
2013-08-09 15:53:02 -07:00
|
|
|
-privileged=false: Give extended privileges to this container
|
2013-04-02 04:52:44 +03:00
|
|
|
-m=0: Memory limit (in bytes)
|
2013-07-21 17:11:47 -07:00
|
|
|
-n=true: Enable networking for this container
|
2013-04-02 04:52:44 +03:00
|
|
|
-p=[]: Map a network port to the container
|
2013-08-15 21:48:05 +03:00
|
|
|
-rm=false: Automatically remove the container when it exits (incompatible with -d)
|
2013-04-02 04:52:44 +03:00
|
|
|
-t=false: Allocate a pseudo-tty
|
|
|
|
-u="": Username or UID
|
2013-08-11 02:04:04 +01:00
|
|
|
-dns=[]: Set custom dns servers for the container
|
2013-07-16 10:14:21 -07:00
|
|
|
-v=[]: Create a bind mount with: [host-dir]:[container-dir]:[rw|ro]. If "host-dir" is missing, then docker creates a new volume.
|
2013-05-02 12:11:57 -07:00
|
|
|
-volumes-from="": Mount all volumes from the given container.
|
2013-06-24 17:20:05 -09:00
|
|
|
-entrypoint="": Overwrite the default entrypoint set by the image.
|
2013-08-15 20:38:17 +02:00
|
|
|
-w="": Working directory inside the container
|
2013-08-15 23:35:03 +00:00
|
|
|
-lxc-conf=[]: Add custom lxc options -lxc-conf="lxc.cgroup.cpuset.cpus = 0,1"
|
2013-07-12 00:50:03 +03:00
|
|
|
|
|
|
|
Examples
|
|
|
|
--------
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
2013-08-13 18:05:35 -07:00
|
|
|
sudo docker run -cidfile /tmp/docker_test.cid ubuntu echo "test"
|
2013-07-12 00:50:03 +03:00
|
|
|
|
2013-08-13 18:05:35 -07:00
|
|
|
This will create a container and print "test" to the console. The
|
|
|
|
``cidfile`` flag makes docker attempt to create a new file and write the
|
|
|
|
container ID to it. If the file exists already, docker will return an
|
|
|
|
error. Docker will close this file when docker run exits.
|
2013-08-09 15:53:02 -07:00
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
docker run mount -t tmpfs none /var/spool/squid
|
|
|
|
|
2013-08-13 18:05:35 -07:00
|
|
|
This will *not* work, because by default, most potentially dangerous
|
|
|
|
kernel capabilities are dropped; including ``cap_sys_admin`` (which is
|
|
|
|
required to mount filesystems). However, the ``-privileged`` flag will
|
|
|
|
allow it to run:
|
2013-08-09 15:53:02 -07:00
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
docker run -privileged mount -t tmpfs none /var/spool/squid
|
|
|
|
|
2013-08-13 18:05:35 -07:00
|
|
|
The ``-privileged`` flag gives *all* capabilities to the container,
|
|
|
|
and it also lifts all the limitations enforced by the ``device``
|
|
|
|
cgroup controller. In other words, the container can then do almost
|
|
|
|
everything that the host can do. This flag exists to allow special
|
|
|
|
use-cases, like running Docker within Docker.
|
|
|
|
|
2013-08-15 20:38:17 +02:00
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
docker run -w /path/to/dir/ -i -t ubuntu pwd
|
|
|
|
|
2013-09-04 10:52:53 +02:00
|
|
|
The ``-w`` lets the command being executed inside directory given,
|
2013-08-15 20:38:17 +02:00
|
|
|
here /path/to/dir/. If the path does not exists it is created inside the
|
|
|
|
container.
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
docker run -v `pwd`:`pwd` -w `pwd` -i -t ubuntu pwd
|
|
|
|
|
|
|
|
The ``-v`` flag mounts the current working directory into the container.
|
2013-09-04 10:52:53 +02:00
|
|
|
The ``-w`` lets the command being executed inside the current
|
|
|
|
working directory, by changing into the directory to the value
|
2013-08-15 20:38:17 +02:00
|
|
|
returned by ``pwd``. So this combination executes the command
|
|
|
|
using the container, but inside the current working directory.
|
|
|
|
|
|
|
|
|