run.rst 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. :title: Run Command
  2. :description: Run a command in a new container
  3. :keywords: run, container, docker, documentation
  4. ===========================================
  5. ``run`` -- Run a command in a new container
  6. ===========================================
  7. ::
  8. Usage: docker run [OPTIONS] IMAGE[:TAG] [COMMAND] [ARG...]
  9. Run a command in a new container
  10. -a=map[]: Attach to stdin, stdout or stderr.
  11. -c=0: CPU shares (relative weight)
  12. -cidfile="": Write the container ID to the file
  13. -d=false: Detached mode: Run container in the background, print new container id
  14. -e=[]: Set environment variables
  15. -h="": Container host name
  16. -i=false: Keep stdin open even if not attached
  17. -privileged=false: Give extended privileges to this container
  18. -m=0: Memory limit (in bytes)
  19. -n=true: Enable networking for this container
  20. -p=[]: Map a network port to the container
  21. -t=false: Allocate a pseudo-tty
  22. -u="": Username or UID
  23. -dns=[]: Set custom dns servers for the container
  24. -v=[]: Create a bind mount with: [host-dir]:[container-dir]:[rw|ro]. If "host-dir" is missing, then docker creates a new volume.
  25. -volumes-from="": Mount all volumes from the given container.
  26. -entrypoint="": Overwrite the default entrypoint set by the image.
  27. Examples
  28. --------
  29. .. code-block:: bash
  30. docker run -cidfile /tmp/docker_test.cid ubuntu echo "test"
  31. | 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.
  32. .. code-block:: bash
  33. docker run mount -t tmpfs none /var/spool/squid
  34. | 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:
  35. .. code-block:: bash
  36. docker run -privileged mount -t tmpfs none /var/spool/squid
  37. | 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.