cli.rst 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369
  1. :title: Command Line Interface
  2. :description: Docker's CLI command description and usage
  3. :keywords: Docker, Docker documentation, CLI, command line
  4. .. _cli:
  5. Command Line Help
  6. -----------------
  7. To list available commands, either run ``docker`` with no parameters or execute
  8. ``docker help``::
  9. $ sudo docker
  10. Usage: docker [OPTIONS] COMMAND [arg...]
  11. -H=[unix:///var/run/docker.sock]: tcp://[host]:port to bind/connect to or unix://[/path/to/socket] to use. When host=[127.0.0.1] is omitted for tcp or path=[/var/run/docker.sock] is omitted for unix sockets, default values are used.
  12. A self-sufficient runtime for linux containers.
  13. ...
  14. .. _cli_options:
  15. Options
  16. -------
  17. Single character commandline options can be combined, so rather than typing
  18. ``docker run -t -i --name test busybox sh``, you can write
  19. ``docker run -ti --name test busybox sh``.
  20. Boolean
  21. ~~~~~~~
  22. Boolean options look like ``-d=false``. The value you see is the
  23. default value which gets set if you do **not** use the boolean
  24. flag. If you do call ``run -d``, that sets the opposite boolean value,
  25. so in this case, ``true``, and so ``docker run -d`` **will** run in
  26. "detached" mode, in the background. Other boolean options are similar
  27. -- specifying them will set the value to the opposite of the default
  28. value.
  29. Multi
  30. ~~~~~
  31. Options like ``-a=[]`` indicate they can be specified multiple times::
  32. docker run -a stdin -a stdout -a stderr -i -t ubuntu /bin/bash
  33. Sometimes this can use a more complex value string, as for ``-v``::
  34. docker run -v /host:/container example/mysql
  35. Strings and Integers
  36. ~~~~~~~~~~~~~~~~~~~~
  37. Options like ``-name=""`` expect a string, and they can only be
  38. specified once. Options like ``-c=0`` expect an integer, and they can
  39. only be specified once.
  40. ----
  41. Commands
  42. --------
  43. .. _cli_daemon:
  44. ``daemon``
  45. ----------
  46. ::
  47. Usage of docker:
  48. -D, --debug=false: Enable debug mode
  49. -H, --host=[]: Multiple tcp://host:port or unix://path/to/socket to bind in daemon mode, single connection otherwise. systemd socket activation can be used with fd://[socketfd].
  50. --api-enable-cors=false: Enable CORS headers in the remote API
  51. -b, --bridge="": Attach containers to a pre-existing network bridge; use 'none' to disable container networking
  52. --bip="": Use this CIDR notation address for the network bridge's IP, not compatible with -b
  53. -d, --daemon=false: Enable daemon mode
  54. --dns=[]: Force docker to use specific DNS servers
  55. -g, --graph="/var/lib/docker": Path to use as the root of the docker runtime
  56. --icc=true: Enable inter-container communication
  57. --ip="0.0.0.0": Default IP address to use when binding container ports
  58. --iptables=true: Disable docker's addition of iptables rules
  59. -p, --pidfile="/var/run/docker.pid": Path to use for daemon PID file
  60. -r, --restart=true: Restart previously running containers
  61. -s, --storage-driver="": Force the docker runtime to use a specific storage driver
  62. -e, --exec-driver="native": Force the docker runtime to use a specific exec driver
  63. -v, --version=false: Print version information and quit
  64. --mtu=0: Set the containers network MTU; if no value is provided: default to the default route MTU or 1500 if no default route is available
  65. The Docker daemon is the persistent process that manages containers. Docker uses the same binary for both the
  66. daemon and client. To run the daemon you provide the ``-d`` flag.
  67. To force Docker to use devicemapper as the storage driver, use ``docker -d -s devicemapper``.
  68. To set the DNS server for all Docker containers, use ``docker -d -dns 8.8.8.8``.
  69. To run the daemon with debug output, use ``docker -d -D``.
  70. To use lxc as the execution driver, use ``docker -d -e lxc``.
  71. The docker client will also honor the ``DOCKER_HOST`` environment variable to set
  72. the ``-H`` flag for the client.
  73. ::
  74. docker -H tcp://0.0.0.0:4243 ps
  75. # or
  76. export DOCKER_HOST="tcp://0.0.0.0:4243"
  77. docker ps
  78. # both are equal
  79. To run the daemon with `systemd socket activation <http://0pointer.de/blog/projects/socket-activation.html>`_, use ``docker -d -H fd://``.
  80. Using ``fd://`` will work perfectly for most setups but you can also specify individual sockets too ``docker -d -H fd://3``.
  81. If the specified socket activated files aren't found then docker will exit.
  82. You can find examples of using systemd socket activation with docker and systemd in the `docker source tree <https://github.com/dotcloud/docker/blob/master/contrib/init/systemd/socket-activation/>`_.
  83. .. warning::
  84. Docker and LXC do not support the use of softlinks for either the Docker data directory (``/var/lib/docker``) or for ``/tmp``.
  85. If your system is likely to be set up in that way, you can use ``readlink -f`` to canonicalise the links:
  86. ``TMPDIR=$(readlink -f /tmp) /usr/local/bin/docker -d -D -g $(readlink -f /var/lib/docker) -H unix:// $EXPOSE_ALL > /var/lib/boot2docker/docker.log 2>&1``
  87. .. _cli_attach:
  88. ``attach``
  89. ----------
  90. ::
  91. Usage: docker attach CONTAINER
  92. Attach to a running container.
  93. --no-stdin=false: Do not attach stdin
  94. --sig-proxy=true: Proxify all received signal to the process (even in non-tty mode)
  95. You can detach from the container again (and leave it running) with
  96. ``CTRL-c`` (for a quiet exit) or ``CTRL-\`` to get a stacktrace of
  97. the Docker client when it quits. When you detach from the container's
  98. process the exit code will be returned to the client.
  99. To stop a container, use ``docker stop``.
  100. To kill the container, use ``docker kill``.
  101. .. _cli_attach_examples:
  102. Examples:
  103. ~~~~~~~~~
  104. .. code-block:: bash
  105. $ ID=$(sudo docker run -d ubuntu /usr/bin/top -b)
  106. $ sudo docker attach $ID
  107. top - 02:05:52 up 3:05, 0 users, load average: 0.01, 0.02, 0.05
  108. Tasks: 1 total, 1 running, 0 sleeping, 0 stopped, 0 zombie
  109. Cpu(s): 0.1%us, 0.2%sy, 0.0%ni, 99.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
  110. Mem: 373572k total, 355560k used, 18012k free, 27872k buffers
  111. Swap: 786428k total, 0k used, 786428k free, 221740k cached
  112. PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
  113. 1 root 20 0 17200 1116 912 R 0 0.3 0:00.03 top
  114. top - 02:05:55 up 3:05, 0 users, load average: 0.01, 0.02, 0.05
  115. Tasks: 1 total, 1 running, 0 sleeping, 0 stopped, 0 zombie
  116. Cpu(s): 0.0%us, 0.2%sy, 0.0%ni, 99.8%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
  117. Mem: 373572k total, 355244k used, 18328k free, 27872k buffers
  118. Swap: 786428k total, 0k used, 786428k free, 221776k cached
  119. PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
  120. 1 root 20 0 17208 1144 932 R 0 0.3 0:00.03 top
  121. top - 02:05:58 up 3:06, 0 users, load average: 0.01, 0.02, 0.05
  122. Tasks: 1 total, 1 running, 0 sleeping, 0 stopped, 0 zombie
  123. Cpu(s): 0.2%us, 0.3%sy, 0.0%ni, 99.5%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
  124. Mem: 373572k total, 355780k used, 17792k free, 27880k buffers
  125. Swap: 786428k total, 0k used, 786428k free, 221776k cached
  126. PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
  127. 1 root 20 0 17208 1144 932 R 0 0.3 0:00.03 top
  128. ^C$
  129. $ sudo docker stop $ID
  130. .. _cli_build:
  131. ``build``
  132. ---------
  133. ::
  134. Usage: docker build [OPTIONS] PATH | URL | -
  135. Build a new container image from the source code at PATH
  136. -t, --tag="": Repository name (and optionally a tag) to be applied
  137. to the resulting image in case of success.
  138. -q, --quiet=false: Suppress the verbose output generated by the containers.
  139. --no-cache: Do not use the cache when building the image.
  140. --rm=true: Remove intermediate containers after a successful build
  141. The files at ``PATH`` or ``URL`` are called the "context" of the build. The
  142. build process may refer to any of the files in the context, for example when
  143. using an :ref:`ADD <dockerfile_add>` instruction. When a single ``Dockerfile``
  144. is given as ``URL``, then no context is set. When a Git repository is set as
  145. ``URL``, then the repository is used as the context. Git repositories are
  146. cloned with their submodules (`git clone --recursive`).
  147. .. _cli_build_examples:
  148. .. seealso:: :ref:`dockerbuilder`.
  149. Examples:
  150. ~~~~~~~~~
  151. .. code-block:: bash
  152. $ sudo docker build .
  153. Uploading context 10240 bytes
  154. Step 1 : FROM busybox
  155. Pulling repository busybox
  156. ---> e9aa60c60128MB/2.284 MB (100%) endpoint: https://cdn-registry-1.docker.io/v1/
  157. Step 2 : RUN ls -lh /
  158. ---> Running in 9c9e81692ae9
  159. total 24
  160. drwxr-xr-x 2 root root 4.0K Mar 12 2013 bin
  161. drwxr-xr-x 5 root root 4.0K Oct 19 00:19 dev
  162. drwxr-xr-x 2 root root 4.0K Oct 19 00:19 etc
  163. drwxr-xr-x 2 root root 4.0K Nov 15 23:34 lib
  164. lrwxrwxrwx 1 root root 3 Mar 12 2013 lib64 -> lib
  165. dr-xr-xr-x 116 root root 0 Nov 15 23:34 proc
  166. lrwxrwxrwx 1 root root 3 Mar 12 2013 sbin -> bin
  167. dr-xr-xr-x 13 root root 0 Nov 15 23:34 sys
  168. drwxr-xr-x 2 root root 4.0K Mar 12 2013 tmp
  169. drwxr-xr-x 2 root root 4.0K Nov 15 23:34 usr
  170. ---> b35f4035db3f
  171. Step 3 : CMD echo Hello World
  172. ---> Running in 02071fceb21b
  173. ---> f52f38b7823e
  174. Successfully built f52f38b7823e
  175. Removing intermediate container 9c9e81692ae9
  176. Removing intermediate container 02071fceb21b
  177. This example specifies that the ``PATH`` is ``.``, and so all the files in
  178. the local directory get tar'd and sent to the Docker daemon. The ``PATH``
  179. specifies where to find the files for the "context" of the build on
  180. the Docker daemon. Remember that the daemon could be running on a
  181. remote machine and that no parsing of the ``Dockerfile`` happens at the
  182. client side (where you're running ``docker build``). That means that
  183. *all* the files at ``PATH`` get sent, not just the ones listed to
  184. :ref:`ADD <dockerfile_add>` in the ``Dockerfile``.
  185. The transfer of context from the local machine to the Docker daemon is
  186. what the ``docker`` client means when you see the "Uploading context"
  187. message.
  188. If you wish to keep the intermediate containers after the build is complete,
  189. you must use ``--rm=false``. This does not affect the build cache.
  190. .. code-block:: bash
  191. $ sudo docker build -t vieux/apache:2.0 .
  192. This will build like the previous example, but it will then tag the
  193. resulting image. The repository name will be ``vieux/apache`` and the
  194. tag will be ``2.0``
  195. .. code-block:: bash
  196. $ sudo docker build - < Dockerfile
  197. This will read a ``Dockerfile`` from *stdin* without context. Due to
  198. the lack of a context, no contents of any local directory will be sent
  199. to the ``docker`` daemon. Since there is no context, a ``Dockerfile``
  200. ``ADD`` only works if it refers to a remote URL.
  201. .. code-block:: bash
  202. $ sudo docker build github.com/creack/docker-firefox
  203. This will clone the GitHub repository and use the cloned repository as
  204. context. The ``Dockerfile`` at the root of the repository is used as
  205. ``Dockerfile``. Note that you can specify an arbitrary Git repository
  206. by using the ``git://`` schema.
  207. .. _cli_commit:
  208. ``commit``
  209. ----------
  210. ::
  211. Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
  212. Create a new image from a container's changes
  213. -m, --message="": Commit message
  214. -a, --author="": Author (eg. "John Hannibal Smith <hannibal@a-team.com>"
  215. --run="": Configuration to be applied when the image is launched with `docker run`.
  216. (ex: -run='{"Cmd": ["cat", "/world"], "PortSpecs": ["22"]}')
  217. .. _cli_commit_examples:
  218. Commit an existing container
  219. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  220. .. code-block:: bash
  221. $ sudo docker ps
  222. ID IMAGE COMMAND CREATED STATUS PORTS
  223. c3f279d17e0a ubuntu:12.04 /bin/bash 7 days ago Up 25 hours
  224. 197387f1b436 ubuntu:12.04 /bin/bash 7 days ago Up 25 hours
  225. $ docker commit c3f279d17e0a SvenDowideit/testimage:version3
  226. f5283438590d
  227. $ docker images | head
  228. REPOSITORY TAG ID CREATED VIRTUAL SIZE
  229. SvenDowideit/testimage version3 f5283438590d 16 seconds ago 335.7 MB
  230. Change the command that a container runs
  231. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  232. Sometimes you have an application container running just a service and you need
  233. to make a quick change and then change it back.
  234. In this example, we run a container with ``ls`` and then change the image to
  235. run ``ls /etc``.
  236. .. code-block:: bash
  237. $ docker run -t -name test ubuntu ls
  238. bin boot dev etc home lib lib64 media mnt opt proc root run sbin selinux srv sys tmp usr var
  239. $ docker commit -run='{"Cmd": ["ls","/etc"]}' test test2
  240. 933d16de9e70005304c1717b5c6f2f39d6fd50752834c6f34a155c70790011eb
  241. $ docker run -t test2
  242. adduser.conf gshadow login.defs rc0.d
  243. alternatives gshadow- logrotate.d rc1.d
  244. apt host.conf lsb-base rc2.d
  245. ...
  246. Full -run example
  247. .................
  248. The ``--run`` JSON hash changes the ``Config`` section when running ``docker inspect CONTAINERID``
  249. or ``config`` when running ``docker inspect IMAGEID``.
  250. (Multiline is okay within a single quote ``'``)
  251. .. code-block:: bash
  252. $ sudo docker commit -run='
  253. {
  254. "Entrypoint" : null,
  255. "Privileged" : false,
  256. "User" : "",
  257. "VolumesFrom" : "",
  258. "Cmd" : ["cat", "-e", "/etc/resolv.conf"],
  259. "Dns" : ["8.8.8.8", "8.8.4.4"],
  260. "MemorySwap" : 0,
  261. "AttachStdin" : false,
  262. "AttachStderr" : false,
  263. "CpuShares" : 0,
  264. "OpenStdin" : false,
  265. "Volumes" : null,
  266. "Hostname" : "122612f45831",
  267. "PortSpecs" : ["22", "80", "443"],
  268. "Image" : "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc",
  269. "Tty" : false,
  270. "Env" : [
  271. "HOME=/",
  272. "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
  273. ],
  274. "StdinOnce" : false,
  275. "Domainname" : "",
  276. "WorkingDir" : "/",
  277. "NetworkDisabled" : false,
  278. "Memory" : 0,
  279. "AttachStdout" : false
  280. }' $CONTAINER_ID
  281. .. _cli_cp:
  282. ``cp``
  283. ------
  284. ::
  285. Usage: docker cp CONTAINER:PATH HOSTPATH
  286. Copy files/folders from the containers filesystem to the host
  287. path. Paths are relative to the root of the filesystem.
  288. .. code-block:: bash
  289. $ sudo docker cp 7bb0e258aefe:/etc/debian_version .
  290. $ sudo docker cp blue_frog:/etc/hosts .
  291. .. _cli_diff:
  292. ``diff``
  293. --------
  294. ::
  295. Usage: docker diff CONTAINER
  296. List the changed files and directories in a container's filesystem
  297. There are 3 events that are listed in the 'diff':
  298. 1. ```A``` - Add
  299. 2. ```D``` - Delete
  300. 3. ```C``` - Change
  301. For example:
  302. .. code-block:: bash
  303. $ sudo docker diff 7bb0e258aefe
  304. C /dev
  305. A /dev/kmsg
  306. C /etc
  307. A /etc/mtab
  308. A /go
  309. A /go/src
  310. A /go/src/github.com
  311. A /go/src/github.com/dotcloud
  312. A /go/src/github.com/dotcloud/docker
  313. A /go/src/github.com/dotcloud/docker/.git
  314. ....
  315. .. _cli_events:
  316. ``events``
  317. ----------
  318. ::
  319. Usage: docker events
  320. Get real time events from the server
  321. --since="": Show previously created events and then stream.
  322. (either seconds since epoch, or date string as below)
  323. .. _cli_events_example:
  324. Examples
  325. ~~~~~~~~
  326. You'll need two shells for this example.
  327. Shell 1: Listening for events
  328. .............................
  329. .. code-block:: bash
  330. $ sudo docker events
  331. Shell 2: Start and Stop a Container
  332. ...................................
  333. .. code-block:: bash
  334. $ sudo docker start 4386fb97867d
  335. $ sudo docker stop 4386fb97867d
  336. Shell 1: (Again .. now showing events)
  337. ......................................
  338. .. code-block:: bash
  339. [2013-09-03 15:49:26 +0200 CEST] 4386fb97867d: (from 12de384bfb10) start
  340. [2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) die
  341. [2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) stop
  342. Show events in the past from a specified time
  343. .............................................
  344. .. code-block:: bash
  345. $ sudo docker events -since 1378216169
  346. [2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) die
  347. [2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) stop
  348. $ sudo docker events -since '2013-09-03'
  349. [2013-09-03 15:49:26 +0200 CEST] 4386fb97867d: (from 12de384bfb10) start
  350. [2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) die
  351. [2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) stop
  352. $ sudo docker events -since '2013-09-03 15:49:29 +0200 CEST'
  353. [2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) die
  354. [2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) stop
  355. .. _cli_export:
  356. ``export``
  357. ----------
  358. ::
  359. Usage: docker export CONTAINER
  360. Export the contents of a filesystem as a tar archive to STDOUT
  361. For example:
  362. .. code-block:: bash
  363. $ sudo docker export red_panda > latest.tar
  364. .. _cli_history:
  365. ``history``
  366. -----------
  367. ::
  368. Usage: docker history [OPTIONS] IMAGE
  369. Show the history of an image
  370. --no-trunc=false: Don't truncate output
  371. -q, --quiet=false: only show numeric IDs
  372. To see how the ``docker:latest`` image was built:
  373. .. code-block:: bash
  374. $ docker history docker
  375. ID CREATED CREATED BY
  376. docker:latest 19 hours ago /bin/sh -c #(nop) ADD . in /go/src/github.com/dotcloud/docker
  377. cf5f2467662d 2 weeks ago /bin/sh -c #(nop) ENTRYPOINT ["hack/dind"]
  378. 3538fbe372bf 2 weeks ago /bin/sh -c #(nop) WORKDIR /go/src/github.com/dotcloud/docker
  379. 7450f65072e5 2 weeks ago /bin/sh -c #(nop) VOLUME /var/lib/docker
  380. b79d62b97328 2 weeks ago /bin/sh -c apt-get install -y -q lxc
  381. 36714852a550 2 weeks ago /bin/sh -c apt-get install -y -q iptables
  382. 8c4c706df1d6 2 weeks ago /bin/sh -c /bin/echo -e '[default]\naccess_key=$AWS_ACCESS_KEY\nsecret_key=$AWS_SECRET_KEYn' > /.s3cfg
  383. b89989433c48 2 weeks ago /bin/sh -c pip install python-magic
  384. a23e640d85b5 2 weeks ago /bin/sh -c pip install s3cmd
  385. 41f54fec7e79 2 weeks ago /bin/sh -c apt-get install -y -q python-pip
  386. d9bc04add907 2 weeks ago /bin/sh -c apt-get install -y -q reprepro dpkg-sig
  387. e74f4760fa70 2 weeks ago /bin/sh -c gem install --no-rdoc --no-ri fpm
  388. 1e43224726eb 2 weeks ago /bin/sh -c apt-get install -y -q ruby1.9.3 rubygems libffi-dev
  389. 460953ae9d7f 2 weeks ago /bin/sh -c #(nop) ENV GOPATH=/go:/go/src/github.com/dotcloud/docker/vendor
  390. 8b63eb1d666b 2 weeks ago /bin/sh -c #(nop) ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/goroot/bin
  391. 3087f3bcedf2 2 weeks ago /bin/sh -c #(nop) ENV GOROOT=/goroot
  392. 635840d198e5 2 weeks ago /bin/sh -c cd /goroot/src && ./make.bash
  393. 439f4a0592ba 2 weeks ago /bin/sh -c curl -s https://go.googlecode.com/files/go1.1.2.src.tar.gz | tar -v -C / -xz && mv /go /goroot
  394. 13967ed36e93 2 weeks ago /bin/sh -c #(nop) ENV CGO_ENABLED=0
  395. bf7424458437 2 weeks ago /bin/sh -c apt-get install -y -q build-essential
  396. a89ec997c3bf 2 weeks ago /bin/sh -c apt-get install -y -q mercurial
  397. b9f165c6e749 2 weeks ago /bin/sh -c apt-get install -y -q git
  398. 17a64374afa7 2 weeks ago /bin/sh -c apt-get install -y -q curl
  399. d5e85dc5b1d8 2 weeks ago /bin/sh -c apt-get update
  400. 13e642467c11 2 weeks ago /bin/sh -c echo 'deb http://archive.ubuntu.com/ubuntu precise main universe' > /etc/apt/sources.list
  401. ae6dde92a94e 2 weeks ago /bin/sh -c #(nop) MAINTAINER Solomon Hykes <solomon@dotcloud.com>
  402. ubuntu:12.04 6 months ago
  403. .. _cli_images:
  404. ``images``
  405. ----------
  406. ::
  407. Usage: docker images [OPTIONS] [NAME]
  408. List images
  409. -a, --all=false: show all images (by default filter out the intermediate images used to build)
  410. --no-trunc=false: Don't truncate output
  411. -q, --quiet=false: only show numeric IDs
  412. --tree=false: output graph in tree format
  413. --viz=false: output graph in graphviz format
  414. Listing the most recently created images
  415. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  416. .. code-block:: bash
  417. $ sudo docker images | head
  418. REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
  419. <none> <none> 77af4d6b9913 19 hours ago 1.089 GB
  420. committest latest b6fa739cedf5 19 hours ago 1.089 GB
  421. <none> <none> 78a85c484f71 19 hours ago 1.089 GB
  422. docker latest 30557a29d5ab 20 hours ago 1.089 GB
  423. <none> <none> 0124422dd9f9 20 hours ago 1.089 GB
  424. <none> <none> 18ad6fad3402 22 hours ago 1.082 GB
  425. <none> <none> f9f1e26352f0 23 hours ago 1.089 GB
  426. tryout latest 2629d1fa0b81 23 hours ago 131.5 MB
  427. <none> <none> 5ed6274db6ce 24 hours ago 1.089 GB
  428. Listing the full length image IDs
  429. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  430. .. code-block:: bash
  431. $ sudo docker images --no-trunc | head
  432. REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
  433. <none> <none> 77af4d6b9913e693e8d0b4b294fa62ade6054e6b2f1ffb617ac955dd63fb0182 19 hours ago 1.089 GB
  434. committest latest b6fa739cedf5ea12a620a439402b6004d057da800f91c7524b5086a5e4749c9f 19 hours ago 1.089 GB
  435. <none> <none> 78a85c484f71509adeaace20e72e941f6bdd2b25b4c75da8693efd9f61a37921 19 hours ago 1.089 GB
  436. docker latest 30557a29d5abc51e5f1d5b472e79b7e296f595abcf19fe6b9199dbbc809c6ff4 20 hours ago 1.089 GB
  437. <none> <none> 0124422dd9f9cf7ef15c0617cda3931ee68346455441d66ab8bdc5b05e9fdce5 20 hours ago 1.089 GB
  438. <none> <none> 18ad6fad340262ac2a636efd98a6d1f0ea775ae3d45240d3418466495a19a81b 22 hours ago 1.082 GB
  439. <none> <none> f9f1e26352f0a3ba6a0ff68167559f64f3e21ff7ada60366e2d44a04befd1d3a 23 hours ago 1.089 GB
  440. tryout latest 2629d1fa0b81b222fca63371ca16cbf6a0772d07759ff80e8d1369b926940074 23 hours ago 131.5 MB
  441. <none> <none> 5ed6274db6ceb2397844896966ea239290555e74ef307030ebb01ff91b1914df 24 hours ago 1.089 GB
  442. Displaying images visually
  443. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  444. .. code-block:: bash
  445. $ sudo docker images --viz | dot -Tpng -o docker.png
  446. .. image:: docker_images.gif
  447. :alt: Example inheritance graph of Docker images.
  448. Displaying image hierarchy
  449. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  450. .. code-block:: bash
  451. $ sudo docker images --tree
  452. ├─8dbd9e392a96 Size: 131.5 MB (virtual 131.5 MB) Tags: ubuntu:12.04,ubuntu:latest,ubuntu:precise
  453. └─27cf78414709 Size: 180.1 MB (virtual 180.1 MB)
  454. └─b750fe79269d Size: 24.65 kB (virtual 180.1 MB) Tags: ubuntu:12.10,ubuntu:quantal
  455. ├─f98de3b610d5 Size: 12.29 kB (virtual 180.1 MB)
  456. │ └─7da80deb7dbf Size: 16.38 kB (virtual 180.1 MB)
  457. │ └─65ed2fee0a34 Size: 20.66 kB (virtual 180.2 MB)
  458. │ └─a2b9ea53dddc Size: 819.7 MB (virtual 999.8 MB)
  459. │ └─a29b932eaba8 Size: 28.67 kB (virtual 999.9 MB)
  460. │ └─e270a44f124d Size: 12.29 kB (virtual 999.9 MB) Tags: progrium/buildstep:latest
  461. └─17e74ac162d8 Size: 53.93 kB (virtual 180.2 MB)
  462. └─339a3f56b760 Size: 24.65 kB (virtual 180.2 MB)
  463. └─904fcc40e34d Size: 96.7 MB (virtual 276.9 MB)
  464. └─b1b0235328dd Size: 363.3 MB (virtual 640.2 MB)
  465. └─7cb05d1acb3b Size: 20.48 kB (virtual 640.2 MB)
  466. └─47bf6f34832d Size: 20.48 kB (virtual 640.2 MB)
  467. └─f165104e82ed Size: 12.29 kB (virtual 640.2 MB)
  468. └─d9cf85a47b7e Size: 1.911 MB (virtual 642.2 MB)
  469. └─3ee562df86ca Size: 17.07 kB (virtual 642.2 MB)
  470. └─b05fc2d00e4a Size: 24.96 kB (virtual 642.2 MB)
  471. └─c96a99614930 Size: 12.29 kB (virtual 642.2 MB)
  472. └─a6a357a48c49 Size: 12.29 kB (virtual 642.2 MB) Tags: ndj/mongodb:latest
  473. .. _cli_import:
  474. ``import``
  475. ----------
  476. ::
  477. Usage: docker import URL|- [REPOSITORY[:TAG]]
  478. Create an empty filesystem image and import the contents of the tarball
  479. (.tar, .tar.gz, .tgz, .bzip, .tar.xz, .txz) into it, then optionally tag it.
  480. At this time, the URL must start with ``http`` and point to a single
  481. file archive (.tar, .tar.gz, .tgz, .bzip, .tar.xz, or .txz) containing a
  482. root filesystem. If you would like to import from a local directory or
  483. archive, you can use the ``-`` parameter to take the data from *stdin*.
  484. Examples
  485. ~~~~~~~~
  486. Import from a remote location
  487. .............................
  488. This will create a new untagged image.
  489. .. code-block:: bash
  490. $ sudo docker import http://example.com/exampleimage.tgz
  491. Import from a local file
  492. ........................
  493. Import to docker via pipe and *stdin*.
  494. .. code-block:: bash
  495. $ cat exampleimage.tgz | sudo docker import - exampleimagelocal:new
  496. Import from a local directory
  497. .............................
  498. .. code-block:: bash
  499. $ sudo tar -c . | docker import - exampleimagedir
  500. Note the ``sudo`` in this example -- you must preserve the ownership of the
  501. files (especially root ownership) during the archiving with tar. If you are not
  502. root (or the sudo command) when you tar, then the ownerships might not get
  503. preserved.
  504. .. _cli_info:
  505. ``info``
  506. --------
  507. ::
  508. Usage: docker info
  509. Display system-wide information.
  510. .. code-block:: bash
  511. $ sudo docker info
  512. Containers: 292
  513. Images: 194
  514. Debug mode (server): false
  515. Debug mode (client): false
  516. Fds: 22
  517. Goroutines: 67
  518. LXC Version: 0.9.0
  519. EventsListeners: 115
  520. Kernel Version: 3.8.0-33-generic
  521. WARNING: No swap limit support
  522. .. _cli_insert:
  523. ``insert``
  524. ----------
  525. ::
  526. Usage: docker insert IMAGE URL PATH
  527. Insert a file from URL in the IMAGE at PATH
  528. Use the specified ``IMAGE`` as the parent for a new image which adds a
  529. :ref:`layer <layer_def>` containing the new file. The ``insert`` command does
  530. not modify the original image, and the new image has the contents of the parent
  531. image, plus the new file.
  532. Examples
  533. ~~~~~~~~
  534. Insert file from GitHub
  535. .......................
  536. .. code-block:: bash
  537. $ sudo docker insert 8283e18b24bc https://raw.github.com/metalivedev/django/master/postinstall /tmp/postinstall.sh
  538. 06fd35556d7b
  539. .. _cli_inspect:
  540. ``inspect``
  541. -----------
  542. ::
  543. Usage: docker inspect CONTAINER|IMAGE [CONTAINER|IMAGE...]
  544. Return low-level information on a container/image
  545. -f, --format="": Format the output using the given go template.
  546. By default, this will render all results in a JSON array. If a format
  547. is specified, the given template will be executed for each result.
  548. Go's `text/template <http://golang.org/pkg/text/template/>`_ package
  549. describes all the details of the format.
  550. Examples
  551. ~~~~~~~~
  552. Get an instance's IP Address
  553. ............................
  554. For the most part, you can pick out any field from the JSON in a
  555. fairly straightforward manner.
  556. .. code-block:: bash
  557. $ sudo docker inspect --format='{{.NetworkSettings.IPAddress}}' $INSTANCE_ID
  558. List All Port Bindings
  559. ......................
  560. One can loop over arrays and maps in the results to produce simple
  561. text output:
  562. .. code-block:: bash
  563. $ sudo docker inspect -format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' $INSTANCE_ID
  564. Find a Specific Port Mapping
  565. ............................
  566. The ``.Field`` syntax doesn't work when the field name begins with a
  567. number, but the template language's ``index`` function does. The
  568. ``.NetworkSettings.Ports`` section contains a map of the internal port
  569. mappings to a list of external address/port objects, so to grab just
  570. the numeric public port, you use ``index`` to find the specific port
  571. map, and then ``index`` 0 contains first object inside of that. Then
  572. we ask for the ``HostPort`` field to get the public address.
  573. .. code-block:: bash
  574. $ sudo docker inspect -format='{{(index (index .NetworkSettings.Ports "8787/tcp") 0).HostPort}}' $INSTANCE_ID
  575. Get config
  576. ..........
  577. The ``.Field`` syntax doesn't work when the field contains JSON data,
  578. but the template language's custom ``json`` function does. The ``.config``
  579. section contains complex json object, so to grab it as JSON, you use ``json``
  580. to convert config object into JSON
  581. .. code-block:: bash
  582. $ sudo docker inspect -format='{{json .config}}' $INSTANCE_ID
  583. .. _cli_kill:
  584. ``kill``
  585. --------
  586. ::
  587. Usage: docker kill [OPTIONS] CONTAINER [CONTAINER...]
  588. Kill a running container (send SIGKILL, or specified signal)
  589. -s, --signal="KILL": Signal to send to the container
  590. The main process inside the container will be sent SIGKILL, or any signal specified with option ``--signal``.
  591. Known Issues (kill)
  592. ~~~~~~~~~~~~~~~~~~~
  593. * :issue:`197` indicates that ``docker kill`` may leave directories
  594. behind and make it difficult to remove the container.
  595. * :issue:`3844` lxc 1.0.0 beta3 removed ``lcx-kill`` which is used by Docker versions before 0.8.0;
  596. see the issue for a workaround.
  597. .. _cli_load:
  598. ``load``
  599. --------
  600. ::
  601. Usage: docker load < repository.tar
  602. Loads a tarred repository from the standard input stream.
  603. Restores both images and tags.
  604. .. _cli_login:
  605. ``login``
  606. ---------
  607. ::
  608. Usage: docker login [OPTIONS] [SERVER]
  609. Register or Login to the docker registry server
  610. -e, --email="": email
  611. -p, --password="": password
  612. -u, --username="": username
  613. If you want to login to a private registry you can
  614. specify this by adding the server name.
  615. example:
  616. docker login localhost:8080
  617. .. _cli_logs:
  618. ``logs``
  619. --------
  620. ::
  621. Usage: docker logs [OPTIONS] CONTAINER
  622. Fetch the logs of a container
  623. -f, --follow=false: Follow log output
  624. The ``docker logs`` command is a convenience which batch-retrieves whatever
  625. logs are present at the time of execution. This does not guarantee execution
  626. order when combined with a ``docker run`` (i.e. your run may not have generated
  627. any logs at the time you execute ``docker logs``).
  628. The ``docker logs --follow`` command combines ``docker logs`` and ``docker attach``:
  629. it will first return all logs from the beginning and then continue streaming
  630. new output from the container's stdout and stderr.
  631. .. _cli_port:
  632. ``port``
  633. --------
  634. ::
  635. Usage: docker port [OPTIONS] CONTAINER PRIVATE_PORT
  636. Lookup the public-facing port which is NAT-ed to PRIVATE_PORT
  637. .. _cli_ps:
  638. ``ps``
  639. ------
  640. ::
  641. Usage: docker ps [OPTIONS]
  642. List containers
  643. -a, --all=false: Show all containers. Only running containers are shown by default.
  644. --no-trunc=false: Don't truncate output
  645. -q, --quiet=false: Only display numeric IDs
  646. Running ``docker ps`` showing 2 linked containers.
  647. .. code-block:: bash
  648. $ docker ps
  649. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  650. 4c01db0b339c ubuntu:12.04 bash 17 seconds ago Up 16 seconds webapp
  651. d7886598dbe2 crosbymichael/redis:latest /redis-server --dir 33 minutes ago Up 33 minutes 6379/tcp redis,webapp/db
  652. fd2645e2e2b5 busybox:latest top 10 days ago Ghost insane_ptolemy
  653. The last container is marked as a ``Ghost`` container. It is a container that was running when the docker daemon was restarted (upgraded, or ``-H`` settings changed). The container is still running, but as this docker daemon process is not able to manage it, you can't attach to it. To bring them out of ``Ghost`` Status, you need to use ``docker kill`` or ``docker restart``.
  654. ``docker ps`` will show only running containers by default. To see all containers: ``docker ps -a``
  655. .. _cli_pull:
  656. ``pull``
  657. --------
  658. ::
  659. Usage: docker pull NAME
  660. Pull an image or a repository from the registry
  661. .. _cli_push:
  662. ``push``
  663. --------
  664. ::
  665. Usage: docker push NAME
  666. Push an image or a repository to the registry
  667. .. _cli_restart:
  668. ``restart``
  669. -----------
  670. ::
  671. Usage: docker restart [OPTIONS] NAME
  672. Restart a running container
  673. .. _cli_rm:
  674. ``rm``
  675. ------
  676. ::
  677. Usage: docker rm [OPTIONS] CONTAINER
  678. Remove one or more containers
  679. --link="": Remove the link instead of the actual container
  680. Known Issues (rm)
  681. ~~~~~~~~~~~~~~~~~
  682. * :issue:`197` indicates that ``docker kill`` may leave directories
  683. behind and make it difficult to remove the container.
  684. Examples:
  685. ~~~~~~~~~
  686. .. code-block:: bash
  687. $ sudo docker rm /redis
  688. /redis
  689. This will remove the container referenced under the link ``/redis``.
  690. .. code-block:: bash
  691. $ sudo docker rm --link /webapp/redis
  692. /webapp/redis
  693. This will remove the underlying link between ``/webapp`` and the ``/redis`` containers removing all
  694. network communication.
  695. .. code-block:: bash
  696. $ sudo docker rm `docker ps -a -q`
  697. This command will delete all stopped containers. The command ``docker ps -a -q`` will return all
  698. existing container IDs and pass them to the ``rm`` command which will delete them. Any running
  699. containers will not be deleted.
  700. .. _cli_rmi:
  701. ``rmi``
  702. -------
  703. ::
  704. Usage: docker rmi IMAGE [IMAGE...]
  705. Remove one or more images
  706. -f, --force=false: Force
  707. Removing tagged images
  708. ~~~~~~~~~~~~~~~~~~~~~~
  709. Images can be removed either by their short or long ID's, or their image names.
  710. If an image has more than one name, each of them needs to be removed before the
  711. image is removed.
  712. .. code-block:: bash
  713. $ sudo docker images
  714. REPOSITORY TAG IMAGE ID CREATED SIZE
  715. test1 latest fd484f19954f 23 seconds ago 7 B (virtual 4.964 MB)
  716. test latest fd484f19954f 23 seconds ago 7 B (virtual 4.964 MB)
  717. test2 latest fd484f19954f 23 seconds ago 7 B (virtual 4.964 MB)
  718. $ sudo docker rmi fd484f19954f
  719. Error: Conflict, cannot delete image fd484f19954f because it is tagged in multiple repositories
  720. 2013/12/11 05:47:16 Error: failed to remove one or more images
  721. $ sudo docker rmi test1
  722. Untagged: fd484f19954f4920da7ff372b5067f5b7ddb2fd3830cecd17b96ea9e286ba5b8
  723. $ sudo docker rmi test2
  724. Untagged: fd484f19954f4920da7ff372b5067f5b7ddb2fd3830cecd17b96ea9e286ba5b8
  725. $ sudo docker images
  726. REPOSITORY TAG IMAGE ID CREATED SIZE
  727. test1 latest fd484f19954f 23 seconds ago 7 B (virtual 4.964 MB)
  728. $ sudo docker rmi test
  729. Untagged: fd484f19954f4920da7ff372b5067f5b7ddb2fd3830cecd17b96ea9e286ba5b8
  730. Deleted: fd484f19954f4920da7ff372b5067f5b7ddb2fd3830cecd17b96ea9e286ba5b8
  731. .. _cli_run:
  732. ``run``
  733. -------
  734. ::
  735. Usage: docker run [OPTIONS] IMAGE[:TAG] [COMMAND] [ARG...]
  736. Run a command in a new container
  737. -a, --attach=map[]: Attach to stdin, stdout or stderr
  738. -c, --cpu-shares=0: CPU shares (relative weight)
  739. --cidfile="": Write the container ID to the file
  740. -d, --detach=false: Detached mode: Run container in the background, print new container id
  741. -e, --env=[]: Set environment variables
  742. -h, --host="": Container host name
  743. -i, --interactive=false: Keep stdin open even if not attached
  744. --privileged=false: Give extended privileges to this container
  745. -m, --memory="": Memory limit (format: <number><optional unit>, where unit = b, k, m or g)
  746. -n, --networking=true: Enable networking for this container
  747. -p, --publish=[]: Map a network port to the container
  748. --rm=false: Automatically remove the container when it exits (incompatible with -d)
  749. -t, --tty=false: Allocate a pseudo-tty
  750. -u, --user="": Username or UID
  751. --dns=[]: Set custom dns servers for the container
  752. -v, --volume=[]: Create a bind mount to a directory or file with: [host-path]:[container-path]:[rw|ro]. If a directory "container-path" is missing, then docker creates a new volume.
  753. --volumes-from="": Mount all volumes from the given container(s)
  754. --entrypoint="": Overwrite the default entrypoint set by the image
  755. -w, --workdir="": Working directory inside the container
  756. --lxc-conf=[]: Add custom lxc options -lxc-conf="lxc.cgroup.cpuset.cpus = 0,1"
  757. --sig-proxy=true: Proxify all received signal to the process (even in non-tty mode)
  758. --expose=[]: Expose a port from the container without publishing it to your host
  759. --link="": Add link to another container (name:alias)
  760. --name="": Assign the specified name to the container. If no name is specific docker will generate a random name
  761. -P, --publish-all=false: Publish all exposed ports to the host interfaces
  762. The ``docker run`` command first ``creates`` a writeable container layer over
  763. the specified image, and then ``starts`` it using the specified command. That
  764. is, ``docker run`` is equivalent to the API ``/containers/create`` then
  765. ``/containers/(id)/start``.
  766. Once the container is stopped it still exists and can be started back up. See ``docker ps -a`` to view a list of all containers.
  767. The ``docker run`` command can be used in combination with ``docker commit`` to
  768. :ref:`change the command that a container runs <cli_commit_examples>`.
  769. See :ref:`port_redirection` for more detailed information about the ``--expose``,
  770. ``-p``, ``-P`` and ``--link`` parameters, and :ref:`working_with_links_names` for
  771. specific examples using ``--link``.
  772. Known Issues (run -volumes-from)
  773. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  774. * :issue:`2702`: "lxc-start: Permission denied - failed to mount"
  775. could indicate a permissions problem with AppArmor. Please see the
  776. issue for a workaround.
  777. Examples:
  778. ~~~~~~~~~
  779. .. code-block:: bash
  780. $ sudo docker run --cidfile /tmp/docker_test.cid ubuntu echo "test"
  781. This will create a container and print ``test`` to the console. The
  782. ``cidfile`` flag makes Docker attempt to create a new file and write the
  783. container ID to it. If the file exists already, Docker will return an
  784. error. Docker will close this file when ``docker run`` exits.
  785. .. code-block:: bash
  786. $ sudo docker run -t -i --rm ubuntu bash
  787. root@bc338942ef20:/# mount -t tmpfs none /mnt
  788. mount: permission denied
  789. This will *not* work, because by default, most potentially dangerous
  790. kernel capabilities are dropped; including ``cap_sys_admin`` (which is
  791. required to mount filesystems). However, the ``-privileged`` flag will
  792. allow it to run:
  793. .. code-block:: bash
  794. $ sudo docker run --privileged ubuntu bash
  795. root@50e3f57e16e6:/# mount -t tmpfs none /mnt
  796. root@50e3f57e16e6:/# df -h
  797. Filesystem Size Used Avail Use% Mounted on
  798. none 1.9G 0 1.9G 0% /mnt
  799. The ``-privileged`` flag gives *all* capabilities to the container,
  800. and it also lifts all the limitations enforced by the ``device``
  801. cgroup controller. In other words, the container can then do almost
  802. everything that the host can do. This flag exists to allow special
  803. use-cases, like running Docker within Docker.
  804. .. code-block:: bash
  805. $ sudo docker run -w /path/to/dir/ -i -t ubuntu pwd
  806. The ``-w`` lets the command being executed inside directory given,
  807. here ``/path/to/dir/``. If the path does not exists it is created inside the
  808. container.
  809. .. code-block:: bash
  810. $ sudo docker run -v `pwd`:`pwd` -w `pwd` -i -t ubuntu pwd
  811. The ``-v`` flag mounts the current working directory into the container.
  812. The ``-w`` lets the command being executed inside the current
  813. working directory, by changing into the directory to the value
  814. returned by ``pwd``. So this combination executes the command
  815. using the container, but inside the current working directory.
  816. .. code-block:: bash
  817. $ sudo docker run -v /doesnt/exist:/foo -w /foo -i -t ubuntu bash
  818. When the host directory of a bind-mounted volume doesn't exist, Docker
  819. will automatically create this directory on the host for you. In the
  820. example above, Docker will create the ``/doesnt/exist`` folder before
  821. starting your container.
  822. .. code-block:: bash
  823. $ sudo docker run -t -i -v /var/run/docker.sock:/var/run/docker.sock -v ./static-docker:/usr/bin/docker busybox sh
  824. By bind-mounting the docker unix socket and statically linked docker binary
  825. (such as that provided by https://get.docker.io), you give the container
  826. the full access to create and manipulate the host's docker daemon.
  827. .. code-block:: bash
  828. $ sudo docker run -p 127.0.0.1:80:8080 ubuntu bash
  829. This binds port ``8080`` of the container to port ``80`` on ``127.0.0.1`` of the
  830. host machine. :ref:`port_redirection` explains in detail how to manipulate ports
  831. in Docker.
  832. .. code-block:: bash
  833. $ sudo docker run --expose 80 ubuntu bash
  834. This exposes port ``80`` of the container for use within a link without
  835. publishing the port to the host system's interfaces. :ref:`port_redirection`
  836. explains in detail how to manipulate ports in Docker.
  837. .. code-block:: bash
  838. $ sudo docker run --name console -t -i ubuntu bash
  839. This will create and run a new container with the container name
  840. being ``console``.
  841. .. code-block:: bash
  842. $ sudo docker run --link /redis:redis --name console ubuntu bash
  843. The ``--link`` flag will link the container named ``/redis`` into the
  844. newly created container with the alias ``redis``. The new container
  845. can access the network and environment of the redis container via
  846. environment variables. The ``--name`` flag will assign the name ``console``
  847. to the newly created container.
  848. .. code-block:: bash
  849. $ sudo docker run --volumes-from 777f7dc92da7,ba8c0c54f0f2:ro -i -t ubuntu pwd
  850. The ``--volumes-from`` flag mounts all the defined volumes from the
  851. referenced containers. Containers can be specified by a comma separated
  852. list or by repetitions of the ``--volumes-from`` argument. The container
  853. ID may be optionally suffixed with ``:ro`` or ``:rw`` to mount the volumes in
  854. read-only or read-write mode, respectively. By default, the volumes are mounted
  855. in the same mode (read write or read only) as the reference container.
  856. A complete example
  857. ..................
  858. .. code-block:: bash
  859. $ sudo docker run -d --name static static-web-files sh
  860. $ sudo docker run -d --expose=8098 --name riak riakserver
  861. $ sudo docker run -d -m 100m -e DEVELOPMENT=1 -e BRANCH=example-code -v $(pwd):/app/bin:ro --name app appserver
  862. $ sudo docker run -d -p 1443:443 --dns=dns.dev.org -v /var/log/httpd --volumes-from static --link riak --link app -h www.sven.dev.org --name web webserver
  863. $ sudo docker run -t -i --rm --volumes-from web -w /var/log/httpd busybox tail -f access.log
  864. This example shows 5 containers that might be set up to test a web application change:
  865. 1. Start a pre-prepared volume image ``static-web-files`` (in the background) that has CSS, image and static HTML in it, (with a ``VOLUME`` instruction in the ``Dockerfile`` to allow the web server to use those files);
  866. 2. Start a pre-prepared ``riakserver`` image, give the container name ``riak`` and expose port ``8098`` to any containers that link to it;
  867. 3. Start the ``appserver`` image, restricting its memory usage to 100MB, setting two environment variables ``DEVELOPMENT`` and ``BRANCH`` and bind-mounting the current directory (``$(pwd)``) in the container in read-only mode as ``/app/bin``;
  868. 4. Start the ``webserver``, mapping port ``443`` in the container to port ``1443`` on the Docker server, setting the DNS server to ``dns.dev.org``, creating a volume to put the log files into (so we can access it from another container), then importing the files from the volume exposed by the ``static`` container, and linking to all exposed ports from ``riak`` and ``app``. Lastly, we set the hostname to ``web.sven.dev.org`` so its consistent with the pre-generated SSL certificate;
  869. 5. Finally, we create a container that runs ``tail -f access.log`` using the logs volume from the ``web`` container, setting the workdir to ``/var/log/httpd``. The ``-rm`` option means that when the container exits, the container's layer is removed.
  870. .. _cli_save:
  871. ``save``
  872. ---------
  873. ::
  874. Usage: docker save image > repository.tar
  875. Streams a tarred repository to the standard output stream.
  876. Contains all parent layers, and all tags + versions.
  877. .. _cli_search:
  878. ``search``
  879. ----------
  880. ::
  881. Usage: docker search TERM
  882. Search the docker index for images
  883. --no-trunc=false: Don't truncate output
  884. -s, --stars=0: Only displays with at least xxx stars
  885. -t, --trusted=false: Only show trusted builds
  886. .. _cli_start:
  887. ``start``
  888. ---------
  889. ::
  890. Usage: docker start [OPTIONS] CONTAINER
  891. Start a stopped container
  892. -a, --attach=false: Attach container's stdout/stderr and forward all signals to the process
  893. -i, --interactive=false: Attach container's stdin
  894. .. _cli_stop:
  895. ``stop``
  896. --------
  897. ::
  898. Usage: docker stop [OPTIONS] CONTAINER [CONTAINER...]
  899. Stop a running container (Send SIGTERM, and then SIGKILL after grace period)
  900. -t, --time=10: Number of seconds to wait for the container to stop before killing it.
  901. The main process inside the container will receive SIGTERM, and after a grace period, SIGKILL
  902. .. _cli_tag:
  903. ``tag``
  904. -------
  905. ::
  906. Usage: docker tag [OPTIONS] IMAGE [REGISTRYHOST/][USERNAME/]NAME[:TAG]
  907. Tag an image into a repository
  908. -f, --force=false: Force
  909. .. _cli_top:
  910. ``top``
  911. -------
  912. ::
  913. Usage: docker top CONTAINER [ps OPTIONS]
  914. Lookup the running processes of a container
  915. .. _cli_version:
  916. ``version``
  917. -----------
  918. Show the version of the Docker client, daemon, and latest released version.
  919. .. _cli_wait:
  920. ``wait``
  921. --------
  922. ::
  923. Usage: docker wait [OPTIONS] NAME
  924. Block until a container stops, then print its exit code.