cli.rst 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081
  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
  12. A self-sufficient runtime for linux containers.
  13. ...
  14. .. _cli_daemon:
  15. ``daemon``
  16. ----------
  17. ::
  18. Usage of docker:
  19. -D=false: Enable debug mode
  20. -H=[unix:///var/run/docker.sock]: Multiple tcp://host:port or unix://path/to/socket to bind in daemon mode, single connection otherwise
  21. -api-enable-cors=false: Enable CORS headers in the remote API
  22. -b="": Attach containers to a pre-existing network bridge; use 'none' to disable container networking
  23. -d=false: Enable daemon mode
  24. -dns="": Force docker to use specific DNS servers
  25. -g="/var/lib/docker": Path to use as the root of the docker runtime
  26. -icc=true: Enable inter-container communication
  27. -ip="0.0.0.0": Default IP address to use when binding container ports
  28. -iptables=true: Disable docker's addition of iptables rules
  29. -p="/var/run/docker.pid": Path to use for daemon PID file
  30. -r=true: Restart previously running containers
  31. -s="": Force the docker runtime to use a specific storage driver
  32. -v=false: Print version information and quit
  33. The docker daemon is the persistent process that manages containers. Docker uses the same binary for both the
  34. daemon and client. To run the daemon you provide the ``-d`` flag.
  35. To force docker to use devicemapper as the storage driver, use ``docker -d -s devicemapper``
  36. To set the dns server for all docker containers, use ``docker -d -dns 8.8.8.8``
  37. To run the daemon with debug output, use ``docker -d -D``
  38. .. _cli_attach:
  39. ``attach``
  40. ----------
  41. ::
  42. Usage: docker attach CONTAINER
  43. Attach to a running container.
  44. -nostdin=false: Do not attach stdin
  45. -sig-proxy=true: Proxify all received signal to the process (even in non-tty mode)
  46. You can detach from the container again (and leave it running) with
  47. ``CTRL-c`` (for a quiet exit) or ``CTRL-\`` to get a stacktrace of
  48. the Docker client when it quits.
  49. To stop a container, use ``docker stop``
  50. To kill the container, use ``docker kill``
  51. .. _cli_attach_examples:
  52. Examples:
  53. ~~~~~~~~~
  54. .. code-block:: bash
  55. $ ID=$(sudo docker run -d ubuntu /usr/bin/top -b)
  56. $ sudo docker attach $ID
  57. top - 02:05:52 up 3:05, 0 users, load average: 0.01, 0.02, 0.05
  58. Tasks: 1 total, 1 running, 0 sleeping, 0 stopped, 0 zombie
  59. 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
  60. Mem: 373572k total, 355560k used, 18012k free, 27872k buffers
  61. Swap: 786428k total, 0k used, 786428k free, 221740k cached
  62. PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
  63. 1 root 20 0 17200 1116 912 R 0 0.3 0:00.03 top
  64. top - 02:05:55 up 3:05, 0 users, load average: 0.01, 0.02, 0.05
  65. Tasks: 1 total, 1 running, 0 sleeping, 0 stopped, 0 zombie
  66. 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
  67. Mem: 373572k total, 355244k used, 18328k free, 27872k buffers
  68. Swap: 786428k total, 0k used, 786428k free, 221776k cached
  69. PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
  70. 1 root 20 0 17208 1144 932 R 0 0.3 0:00.03 top
  71. top - 02:05:58 up 3:06, 0 users, load average: 0.01, 0.02, 0.05
  72. Tasks: 1 total, 1 running, 0 sleeping, 0 stopped, 0 zombie
  73. 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
  74. Mem: 373572k total, 355780k used, 17792k free, 27880k buffers
  75. Swap: 786428k total, 0k used, 786428k free, 221776k cached
  76. PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
  77. 1 root 20 0 17208 1144 932 R 0 0.3 0:00.03 top
  78. ^C$
  79. $ sudo docker stop $ID
  80. .. _cli_build:
  81. ``build``
  82. ---------
  83. ::
  84. Usage: docker build [OPTIONS] PATH | URL | -
  85. Build a new container image from the source code at PATH
  86. -t="": Repository name (and optionally a tag) to be applied
  87. to the resulting image in case of success.
  88. -q=false: Suppress verbose build output.
  89. -no-cache: Do not use the cache when building the image.
  90. -rm: Remove intermediate containers after a successful build
  91. The files at PATH or URL are called the "context" of the build. The
  92. build process may refer to any of the files in the context, for
  93. example when using an :ref:`ADD <dockerfile_add>` instruction. When a
  94. single ``Dockerfile`` is given as URL, then no context is set. When a
  95. git repository is set as URL, then the repository is used as the
  96. context
  97. .. _cli_build_examples:
  98. .. seealso:: :ref:`dockerbuilder`.
  99. Examples:
  100. ~~~~~~~~~
  101. .. code-block:: bash
  102. sudo docker build .
  103. Uploading context 10240 bytes
  104. Step 1 : FROM busybox
  105. Pulling repository busybox
  106. ---> e9aa60c60128MB/2.284 MB (100%) endpoint: https://cdn-registry-1.docker.io/v1/
  107. Step 2 : RUN ls -lh /
  108. ---> Running in 9c9e81692ae9
  109. total 24
  110. drwxr-xr-x 2 root root 4.0K Mar 12 2013 bin
  111. drwxr-xr-x 5 root root 4.0K Oct 19 00:19 dev
  112. drwxr-xr-x 2 root root 4.0K Oct 19 00:19 etc
  113. drwxr-xr-x 2 root root 4.0K Nov 15 23:34 lib
  114. lrwxrwxrwx 1 root root 3 Mar 12 2013 lib64 -> lib
  115. dr-xr-xr-x 116 root root 0 Nov 15 23:34 proc
  116. lrwxrwxrwx 1 root root 3 Mar 12 2013 sbin -> bin
  117. dr-xr-xr-x 13 root root 0 Nov 15 23:34 sys
  118. drwxr-xr-x 2 root root 4.0K Mar 12 2013 tmp
  119. drwxr-xr-x 2 root root 4.0K Nov 15 23:34 usr
  120. ---> b35f4035db3f
  121. Step 3 : CMD echo Hello World
  122. ---> Running in 02071fceb21b
  123. ---> f52f38b7823e
  124. Successfully built f52f38b7823e
  125. This example specifies that the PATH is ``.``, and so all the files in
  126. the local directory get tar'd and sent to the Docker daemon. The PATH
  127. specifies where to find the files for the "context" of the build on
  128. the Docker daemon. Remember that the daemon could be running on a
  129. remote machine and that no parsing of the Dockerfile happens at the
  130. client side (where you're running ``docker build``). That means that
  131. *all* the files at PATH get sent, not just the ones listed to
  132. :ref:`ADD <dockerfile_add>` in the ``Dockerfile``.
  133. The transfer of context from the local machine to the Docker daemon is
  134. what the ``docker`` client means when you see the "Uploading context"
  135. message.
  136. .. code-block:: bash
  137. sudo docker build -t vieux/apache:2.0 .
  138. This will build like the previous example, but it will then tag the
  139. resulting image. The repository name will be ``vieux/apache`` and the
  140. tag will be ``2.0``
  141. .. code-block:: bash
  142. sudo docker build - < Dockerfile
  143. This will read a ``Dockerfile`` from *stdin* without context. Due to
  144. the lack of a context, no contents of any local directory will be sent
  145. to the ``docker`` daemon. Since there is no context, a Dockerfile
  146. ``ADD`` only works if it refers to a remote URL.
  147. .. code-block:: bash
  148. sudo docker build github.com/creack/docker-firefox
  149. This will clone the Github repository and use the cloned repository as
  150. context. The ``Dockerfile`` at the root of the repository is used as
  151. ``Dockerfile``. Note that you can specify an arbitrary git repository
  152. by using the ``git://`` schema.
  153. .. _cli_commit:
  154. ``commit``
  155. ----------
  156. ::
  157. Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
  158. Create a new image from a container's changes
  159. -m="": Commit message
  160. -author="": Author (eg. "John Hannibal Smith <hannibal@a-team.com>"
  161. -run="": Configuration to be applied when the image is launched with `docker run`.
  162. (ex: -run='{"Cmd": ["cat", "/world"], "PortSpecs": ["22"]}')
  163. Simple commit of an existing container
  164. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  165. .. code-block:: bash
  166. $ docker ps
  167. ID IMAGE COMMAND CREATED STATUS PORTS
  168. c3f279d17e0a ubuntu:12.04 /bin/bash 7 days ago Up 25 hours
  169. 197387f1b436 ubuntu:12.04 /bin/bash 7 days ago Up 25 hours
  170. $ docker commit c3f279d17e0a SvenDowideit/testimage:version3
  171. f5283438590d
  172. $ docker images | head
  173. REPOSITORY TAG ID CREATED SIZE
  174. SvenDowideit/testimage version3 f5283438590d 16 seconds ago 204.2 MB (virtual 335.7 MB)
  175. Full -run example
  176. .................
  177. (multiline is ok within a single quote ``'``)
  178. ::
  179. $ sudo docker commit -run='
  180. {
  181. "Entrypoint" : null,
  182. "Privileged" : false,
  183. "User" : "",
  184. "VolumesFrom" : "",
  185. "Cmd" : ["cat", "-e", "/etc/resolv.conf"],
  186. "Dns" : ["8.8.8.8", "8.8.4.4"],
  187. "MemorySwap" : 0,
  188. "AttachStdin" : false,
  189. "AttachStderr" : false,
  190. "CpuShares" : 0,
  191. "OpenStdin" : false,
  192. "Volumes" : null,
  193. "Hostname" : "122612f45831",
  194. "PortSpecs" : ["22", "80", "443"],
  195. "Image" : "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc",
  196. "Tty" : false,
  197. "Env" : [
  198. "HOME=/",
  199. "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
  200. ],
  201. "StdinOnce" : false,
  202. "Domainname" : "",
  203. "WorkingDir" : "/",
  204. "NetworkDisabled" : false,
  205. "Memory" : 0,
  206. "AttachStdout" : false
  207. }' $CONTAINER_ID
  208. .. _cli_cp:
  209. ``cp``
  210. ------
  211. ::
  212. Usage: docker cp CONTAINER:PATH HOSTPATH
  213. Copy files/folders from the containers filesystem to the host
  214. path. Paths are relative to the root of the filesystem.
  215. .. code-block:: bash
  216. $ sudo docker cp 7bb0e258aefe:/etc/debian_version .
  217. $ sudo docker cp blue_frog:/etc/hosts .
  218. .. _cli_diff:
  219. ``diff``
  220. --------
  221. ::
  222. Usage: docker diff CONTAINER
  223. List the changed files and directories in a container's filesystem
  224. There are 3 events that are listed in the 'diff':
  225. 1. ```A``` - Add
  226. 2. ```D``` - Delete
  227. 3. ```C``` - Change
  228. for example:
  229. .. code-block:: bash
  230. $ sudo docker diff 7bb0e258aefe
  231. C /dev
  232. A /dev/kmsg
  233. C /etc
  234. A /etc/mtab
  235. A /go
  236. A /go/src
  237. A /go/src/github.com
  238. A /go/src/github.com/dotcloud
  239. A /go/src/github.com/dotcloud/docker
  240. A /go/src/github.com/dotcloud/docker/.git
  241. ....
  242. .. _cli_events:
  243. ``events``
  244. ----------
  245. ::
  246. Usage: docker events
  247. Get real time events from the server
  248. -since="": Show previously created events and then stream.
  249. (either seconds since epoch, or date string as below)
  250. .. _cli_events_example:
  251. Examples
  252. ~~~~~~~~
  253. You'll need two shells for this example.
  254. Shell 1: Listening for events
  255. .............................
  256. .. code-block:: bash
  257. $ sudo docker events
  258. Shell 2: Start and Stop a Container
  259. ...................................
  260. .. code-block:: bash
  261. $ sudo docker start 4386fb97867d
  262. $ sudo docker stop 4386fb97867d
  263. Shell 1: (Again .. now showing events)
  264. ......................................
  265. .. code-block:: bash
  266. [2013-09-03 15:49:26 +0200 CEST] 4386fb97867d: (from 12de384bfb10) start
  267. [2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) die
  268. [2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) stop
  269. Show events in the past from a specified time
  270. .............................................
  271. .. code-block:: bash
  272. $ sudo docker events -since 1378216169
  273. [2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) die
  274. [2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) stop
  275. $ sudo docker events -since '2013-09-03'
  276. [2013-09-03 15:49:26 +0200 CEST] 4386fb97867d: (from 12de384bfb10) start
  277. [2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) die
  278. [2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) stop
  279. $ sudo docker events -since '2013-09-03 15:49:29 +0200 CEST'
  280. [2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) die
  281. [2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) stop
  282. .. _cli_export:
  283. ``export``
  284. ----------
  285. ::
  286. Usage: docker export CONTAINER
  287. Export the contents of a filesystem as a tar archive to STDOUT
  288. for example:
  289. .. code-block:: bash
  290. $ sudo docker export red_panda > latest.tar
  291. .. _cli_history:
  292. ``history``
  293. -----------
  294. ::
  295. Usage: docker history [OPTIONS] IMAGE
  296. Show the history of an image
  297. -notrunc=false: Don't truncate output
  298. -q=false: only show numeric IDs
  299. To see how the docker:latest image was built:
  300. .. code-block:: bash
  301. $ docker history docker
  302. ID CREATED CREATED BY
  303. docker:latest 19 hours ago /bin/sh -c #(nop) ADD . in /go/src/github.com/dotcloud/docker
  304. cf5f2467662d 2 weeks ago /bin/sh -c #(nop) ENTRYPOINT ["hack/dind"]
  305. 3538fbe372bf 2 weeks ago /bin/sh -c #(nop) WORKDIR /go/src/github.com/dotcloud/docker
  306. 7450f65072e5 2 weeks ago /bin/sh -c #(nop) VOLUME /var/lib/docker
  307. b79d62b97328 2 weeks ago /bin/sh -c apt-get install -y -q lxc
  308. 36714852a550 2 weeks ago /bin/sh -c apt-get install -y -q iptables
  309. 8c4c706df1d6 2 weeks ago /bin/sh -c /bin/echo -e '[default]\naccess_key=$AWS_ACCESS_KEY\nsecret_key=$AWS_SECRET_KEYn' > /.s3cfg
  310. b89989433c48 2 weeks ago /bin/sh -c pip install python-magic
  311. a23e640d85b5 2 weeks ago /bin/sh -c pip install s3cmd
  312. 41f54fec7e79 2 weeks ago /bin/sh -c apt-get install -y -q python-pip
  313. d9bc04add907 2 weeks ago /bin/sh -c apt-get install -y -q reprepro dpkg-sig
  314. e74f4760fa70 2 weeks ago /bin/sh -c gem install --no-rdoc --no-ri fpm
  315. 1e43224726eb 2 weeks ago /bin/sh -c apt-get install -y -q ruby1.9.3 rubygems libffi-dev
  316. 460953ae9d7f 2 weeks ago /bin/sh -c #(nop) ENV GOPATH=/go:/go/src/github.com/dotcloud/docker/vendor
  317. 8b63eb1d666b 2 weeks ago /bin/sh -c #(nop) ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/goroot/bin
  318. 3087f3bcedf2 2 weeks ago /bin/sh -c #(nop) ENV GOROOT=/goroot
  319. 635840d198e5 2 weeks ago /bin/sh -c cd /goroot/src && ./make.bash
  320. 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
  321. 13967ed36e93 2 weeks ago /bin/sh -c #(nop) ENV CGO_ENABLED=0
  322. bf7424458437 2 weeks ago /bin/sh -c apt-get install -y -q build-essential
  323. a89ec997c3bf 2 weeks ago /bin/sh -c apt-get install -y -q mercurial
  324. b9f165c6e749 2 weeks ago /bin/sh -c apt-get install -y -q git
  325. 17a64374afa7 2 weeks ago /bin/sh -c apt-get install -y -q curl
  326. d5e85dc5b1d8 2 weeks ago /bin/sh -c apt-get update
  327. 13e642467c11 2 weeks ago /bin/sh -c echo 'deb http://archive.ubuntu.com/ubuntu precise main universe' > /etc/apt/sources.list
  328. ae6dde92a94e 2 weeks ago /bin/sh -c #(nop) MAINTAINER Solomon Hykes <solomon@dotcloud.com>
  329. ubuntu:12.04 6 months ago
  330. .. _cli_images:
  331. ``images``
  332. ----------
  333. ::
  334. Usage: docker images [OPTIONS] [NAME]
  335. List images
  336. -a=false: show all images (by default filter out the intermediate images used to build)
  337. -notrunc=false: Don't truncate output
  338. -q=false: only show numeric IDs
  339. -tree=false: output graph in tree format
  340. -viz=false: output graph in graphviz format
  341. Listing the most recently created images
  342. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  343. .. code-block:: bash
  344. $ sudo docker images | head
  345. REPOSITORY TAG IMAGE ID CREATED SIZE
  346. <none> <none> 77af4d6b9913 19 hours ago 30.53 MB (virtual 1.089 GB)
  347. committest latest b6fa739cedf5 19 hours ago 30.53 MB (virtual 1.089 GB)
  348. <none> <none> 78a85c484f71 19 hours ago 30.53 MB (virtual 1.089 GB)
  349. docker latest 30557a29d5ab 20 hours ago 30.53 MB (virtual 1.089 GB)
  350. <none> <none> 0124422dd9f9 20 hours ago 30.53 MB (virtual 1.089 GB)
  351. <none> <none> 18ad6fad3402 22 hours ago 23.68 MB (virtual 1.082 GB)
  352. <none> <none> f9f1e26352f0 23 hours ago 30.46 MB (virtual 1.089 GB)
  353. tryout latest 2629d1fa0b81 23 hours ago 16.4 kB (virtual 131.5 MB)
  354. <none> <none> 5ed6274db6ce 24 hours ago 30.44 MB (virtual 1.089 GB)
  355. Listing the full length image IDs
  356. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  357. .. code-block:: bash
  358. $ sudo docker images -notrunc | head
  359. REPOSITORY TAG IMAGE ID CREATED SIZE
  360. <none> <none> 77af4d6b9913e693e8d0b4b294fa62ade6054e6b2f1ffb617ac955dd63fb0182 19 hours ago 30.53 MB (virtual 1.089 GB)
  361. committest latest b6fa739cedf5ea12a620a439402b6004d057da800f91c7524b5086a5e4749c9f 19 hours ago 30.53 MB (virtual 1.089 GB)
  362. <none> <none> 78a85c484f71509adeaace20e72e941f6bdd2b25b4c75da8693efd9f61a37921 19 hours ago 30.53 MB (virtual 1.089 GB)
  363. docker latest 30557a29d5abc51e5f1d5b472e79b7e296f595abcf19fe6b9199dbbc809c6ff4 20 hours ago 30.53 MB (virtual 1.089 GB)
  364. <none> <none> 0124422dd9f9cf7ef15c0617cda3931ee68346455441d66ab8bdc5b05e9fdce5 20 hours ago 30.53 MB (virtual 1.089 GB)
  365. <none> <none> 18ad6fad340262ac2a636efd98a6d1f0ea775ae3d45240d3418466495a19a81b 22 hours ago 23.68 MB (virtual 1.082 GB)
  366. <none> <none> f9f1e26352f0a3ba6a0ff68167559f64f3e21ff7ada60366e2d44a04befd1d3a 23 hours ago 30.46 MB (virtual 1.089 GB)
  367. tryout latest 2629d1fa0b81b222fca63371ca16cbf6a0772d07759ff80e8d1369b926940074 23 hours ago 16.4 kB (virtual 131.5 MB)
  368. <none> <none> 5ed6274db6ceb2397844896966ea239290555e74ef307030ebb01ff91b1914df 24 hours ago 30.44 MB (virtual 1.089 GB)
  369. Displaying images visually
  370. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  371. .. code-block:: bash
  372. $ sudo docker images -viz | dot -Tpng -o docker.png
  373. .. image:: docker_images.gif
  374. :alt: Example inheritance graph of Docker images.
  375. Displaying image hierarchy
  376. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  377. .. code-block:: bash
  378. $ sudo docker images -tree
  379. |─8dbd9e392a96 Size: 131.5 MB (virtual 131.5 MB) Tags: ubuntu:12.04,ubuntu:latest,ubuntu:precise
  380. └─27cf78414709 Size: 180.1 MB (virtual 180.1 MB)
  381. └─b750fe79269d Size: 24.65 kB (virtual 180.1 MB) Tags: ubuntu:12.10,ubuntu:quantal
  382. |─f98de3b610d5 Size: 12.29 kB (virtual 180.1 MB)
  383. | └─7da80deb7dbf Size: 16.38 kB (virtual 180.1 MB)
  384. | └─65ed2fee0a34 Size: 20.66 kB (virtual 180.2 MB)
  385. | └─a2b9ea53dddc Size: 819.7 MB (virtual 999.8 MB)
  386. | └─a29b932eaba8 Size: 28.67 kB (virtual 999.9 MB)
  387. | └─e270a44f124d Size: 12.29 kB (virtual 999.9 MB) Tags: progrium/buildstep:latest
  388. └─17e74ac162d8 Size: 53.93 kB (virtual 180.2 MB)
  389. └─339a3f56b760 Size: 24.65 kB (virtual 180.2 MB)
  390. └─904fcc40e34d Size: 96.7 MB (virtual 276.9 MB)
  391. └─b1b0235328dd Size: 363.3 MB (virtual 640.2 MB)
  392. └─7cb05d1acb3b Size: 20.48 kB (virtual 640.2 MB)
  393. └─47bf6f34832d Size: 20.48 kB (virtual 640.2 MB)
  394. └─f165104e82ed Size: 12.29 kB (virtual 640.2 MB)
  395. └─d9cf85a47b7e Size: 1.911 MB (virtual 642.2 MB)
  396. └─3ee562df86ca Size: 17.07 kB (virtual 642.2 MB)
  397. └─b05fc2d00e4a Size: 24.96 kB (virtual 642.2 MB)
  398. └─c96a99614930 Size: 12.29 kB (virtual 642.2 MB)
  399. └─a6a357a48c49 Size: 12.29 kB (virtual 642.2 MB) Tags: ndj/mongodb:latest
  400. .. _cli_import:
  401. ``import``
  402. ----------
  403. ::
  404. Usage: docker import URL|- [REPOSITORY[:TAG]]
  405. Create a new filesystem image from the contents of a tarball
  406. At this time, the URL must start with ``http`` and point to a single
  407. file archive (.tar, .tar.gz, .tgz, .bzip, .tar.xz, .txz) containing a
  408. root filesystem. If you would like to import from a local directory or
  409. archive, you can use the ``-`` parameter to take the data from
  410. standard in.
  411. Examples
  412. ~~~~~~~~
  413. Import from a remote location
  414. .............................
  415. This will create a new untagged image.
  416. ``$ sudo docker import http://example.com/exampleimage.tgz``
  417. Import from a local file
  418. ........................
  419. Import to docker via pipe and standard in
  420. ``$ cat exampleimage.tgz | sudo docker import - exampleimagelocal:new``
  421. Import from a local directory
  422. .............................
  423. ``$ sudo tar -c . | docker import - exampleimagedir``
  424. Note the ``sudo`` in this example -- you must preserve the ownership
  425. of the files (especially root ownership) during the archiving with
  426. tar. If you are not root (or sudo) when you tar, then the ownerships
  427. might not get preserved.
  428. .. _cli_info:
  429. ``info``
  430. --------
  431. ::
  432. Usage: docker info
  433. Display system-wide information.
  434. .. code-block:: bash
  435. $ sudo docker info
  436. Containers: 292
  437. Images: 194
  438. Debug mode (server): false
  439. Debug mode (client): false
  440. Fds: 22
  441. Goroutines: 67
  442. LXC Version: 0.9.0
  443. EventsListeners: 115
  444. Kernel Version: 3.8.0-33-generic
  445. WARNING: No swap limit support
  446. .. _cli_insert:
  447. ``insert``
  448. ----------
  449. ::
  450. Usage: docker insert IMAGE URL PATH
  451. Insert a file from URL in the IMAGE at PATH
  452. Use the specified IMAGE as the parent for a new image which adds a
  453. :ref:`layer <layer_def>` containing the new file. ``insert`` does not modify
  454. the original image, and the new image has the contents of the parent image,
  455. plus the new file.
  456. Examples
  457. ~~~~~~~~
  458. Insert file from github
  459. .......................
  460. .. code-block:: bash
  461. $ sudo docker insert 8283e18b24bc https://raw.github.com/metalivedev/django/master/postinstall /tmp/postinstall.sh
  462. 06fd35556d7b
  463. .. _cli_inspect:
  464. ``inspect``
  465. -----------
  466. ::
  467. Usage: docker inspect [OPTIONS] CONTAINER
  468. Return low-level information on a container
  469. .. _cli_kill:
  470. ``kill``
  471. --------
  472. ::
  473. Usage: docker kill CONTAINER [CONTAINER...]
  474. Kill a running container (Send SIGKILL)
  475. The main process inside the container will be sent SIGKILL.
  476. Known Issues (kill)
  477. ~~~~~~~~~~~~~~~~~~~
  478. * :issue:`197` indicates that ``docker kill`` may leave directories
  479. behind and make it difficult to remove the container.
  480. .. _cli_load:
  481. ``load``
  482. --------
  483. ::
  484. Usage: docker load < repository.tar
  485. Loads a tarred repository from the standard input stream.
  486. Restores both images and tags.
  487. .. _cli_login:
  488. ``login``
  489. ---------
  490. ::
  491. Usage: docker login [OPTIONS] [SERVER]
  492. Register or Login to the docker registry server
  493. -e="": email
  494. -p="": password
  495. -u="": username
  496. If you want to login to a private registry you can
  497. specify this by adding the server name.
  498. example:
  499. docker login localhost:8080
  500. .. _cli_logs:
  501. ``logs``
  502. --------
  503. ::
  504. Usage: docker logs [OPTIONS] CONTAINER
  505. Fetch the logs of a container
  506. .. _cli_port:
  507. ``port``
  508. --------
  509. ::
  510. Usage: docker port [OPTIONS] CONTAINER PRIVATE_PORT
  511. Lookup the public-facing port which is NAT-ed to PRIVATE_PORT
  512. .. _cli_ps:
  513. ``ps``
  514. ------
  515. ::
  516. Usage: docker ps [OPTIONS]
  517. List containers
  518. -a=false: Show all containers. Only running containers are shown by default.
  519. -notrunc=false: Don't truncate output
  520. -q=false: Only display numeric IDs
  521. .. _cli_pull:
  522. ``pull``
  523. --------
  524. ::
  525. Usage: docker pull NAME
  526. Pull an image or a repository from the registry
  527. .. _cli_push:
  528. ``push``
  529. --------
  530. ::
  531. Usage: docker push NAME
  532. Push an image or a repository to the registry
  533. .. _cli_restart:
  534. ``restart``
  535. -----------
  536. ::
  537. Usage: docker restart [OPTIONS] NAME
  538. Restart a running container
  539. .. _cli_rm:
  540. ``rm``
  541. ------
  542. ::
  543. Usage: docker rm [OPTIONS] CONTAINER
  544. Remove one or more containers
  545. -link="": Remove the link instead of the actual container
  546. Known Issues (rm)
  547. ~~~~~~~~~~~~~~~~~
  548. * :issue:`197` indicates that ``docker kill`` may leave directories
  549. behind and make it difficult to remove the container.
  550. Examples:
  551. ~~~~~~~~~
  552. .. code-block:: bash
  553. $ docker rm /redis
  554. /redis
  555. This will remove the container referenced under the link ``/redis``.
  556. .. code-block:: bash
  557. $ docker rm -link /webapp/redis
  558. /webapp/redis
  559. This will remove the underlying link between ``/webapp`` and the ``/redis`` containers removing all
  560. network communication.
  561. .. code-block:: bash
  562. $ docker rm `docker ps -a -q`
  563. This command will delete all stopped containers. The command ``docker ps -a -q`` will return all
  564. existing container IDs and pass them to the ``rm`` command which will delete them. Any running
  565. containers will not be deleted.
  566. .. _cli_rmi:
  567. ``rmi``
  568. -------
  569. ::
  570. Usage: docker rmi IMAGE [IMAGE...]
  571. Remove one or more images
  572. .. _cli_run:
  573. ``run``
  574. -------
  575. ::
  576. Usage: docker run [OPTIONS] IMAGE[:TAG] [COMMAND] [ARG...]
  577. Run a command in a new container
  578. -a=map[]: Attach to stdin, stdout or stderr
  579. -c=0: CPU shares (relative weight)
  580. -cidfile="": Write the container ID to the file
  581. -d=false: Detached mode: Run container in the background, print new container id
  582. -e=[]: Set environment variables
  583. -h="": Container host name
  584. -i=false: Keep stdin open even if not attached
  585. -privileged=false: Give extended privileges to this container
  586. -m="": Memory limit (format: <number><optional unit>, where unit = b, k, m or g)
  587. -n=true: Enable networking for this container
  588. -p=[]: Map a network port to the container
  589. -rm=false: Automatically remove the container when it exits (incompatible with -d)
  590. -t=false: Allocate a pseudo-tty
  591. -u="": Username or UID
  592. -dns=[]: Set custom dns servers for the container
  593. -v=[]: Create a bind mount with: [host-dir]:[container-dir]:[rw|ro]. If "container-dir" is missing, then docker creates a new volume.
  594. -volumes-from="": Mount all volumes from the given container(s)
  595. -entrypoint="": Overwrite the default entrypoint set by the image
  596. -w="": Working directory inside the container
  597. -lxc-conf=[]: Add custom lxc options -lxc-conf="lxc.cgroup.cpuset.cpus = 0,1"
  598. -sig-proxy=true: Proxify all received signal to the process (even in non-tty mode)
  599. -expose=[]: Expose a port from the container without publishing it to your host
  600. -link="": Add link to another container (name:alias)
  601. -name="": Assign the specified name to the container. If no name is specific docker will generate a random name
  602. -P=false: Publish all exposed ports to the host interfaces
  603. Known Issues (run -volumes-from)
  604. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  605. * :issue:`2702`: "lxc-start: Permission denied - failed to mount"
  606. could indicate a permissions problem with AppArmor. Please see the
  607. issue for a workaround.
  608. Examples:
  609. ~~~~~~~~~
  610. .. code-block:: bash
  611. sudo docker run -cidfile /tmp/docker_test.cid ubuntu echo "test"
  612. This will create a container and print "test" to the console. The
  613. ``cidfile`` flag makes docker attempt to create a new file and write the
  614. container ID to it. If the file exists already, docker will return an
  615. error. Docker will close this file when docker run exits.
  616. .. code-block:: bash
  617. docker run mount -t tmpfs none /var/spool/squid
  618. This will *not* work, because by default, most potentially dangerous
  619. kernel capabilities are dropped; including ``cap_sys_admin`` (which is
  620. required to mount filesystems). However, the ``-privileged`` flag will
  621. allow it to run:
  622. .. code-block:: bash
  623. docker run -privileged mount -t tmpfs none /var/spool/squid
  624. The ``-privileged`` flag gives *all* capabilities to the container,
  625. and it also lifts all the limitations enforced by the ``device``
  626. cgroup controller. In other words, the container can then do almost
  627. everything that the host can do. This flag exists to allow special
  628. use-cases, like running Docker within Docker.
  629. .. code-block:: bash
  630. docker run -w /path/to/dir/ -i -t ubuntu pwd
  631. The ``-w`` lets the command being executed inside directory given,
  632. here /path/to/dir/. If the path does not exists it is created inside the
  633. container.
  634. .. code-block:: bash
  635. docker run -v `pwd`:`pwd` -w `pwd` -i -t ubuntu pwd
  636. The ``-v`` flag mounts the current working directory into the container.
  637. The ``-w`` lets the command being executed inside the current
  638. working directory, by changing into the directory to the value
  639. returned by ``pwd``. So this combination executes the command
  640. using the container, but inside the current working directory.
  641. .. code-block:: bash
  642. docker run -p 127.0.0.1:80:8080 ubuntu bash
  643. This binds port ``8080`` of the container to port ``80`` on 127.0.0.1 of the
  644. host machine. :ref:`port_redirection` explains in detail how to manipulate ports
  645. in Docker.
  646. .. code-block:: bash
  647. docker run -expose 80 ubuntu bash
  648. This exposes port ``80`` of the container for use within a link without
  649. publishing the port to the host system's interfaces. :ref:`port_redirection`
  650. explains in detail how to manipulate ports in Docker.
  651. .. code-block:: bash
  652. docker run -name console -t -i ubuntu bash
  653. This will create and run a new container with the container name
  654. being ``console``.
  655. .. code-block:: bash
  656. docker run -link /redis:redis -name console ubuntu bash
  657. The ``-link`` flag will link the container named ``/redis`` into the
  658. newly created container with the alias ``redis``. The new container
  659. can access the network and environment of the redis container via
  660. environment variables. The ``-name`` flag will assign the name ``console``
  661. to the newly created container.
  662. .. code-block:: bash
  663. docker run -volumes-from 777f7dc92da7,ba8c0c54f0f2:ro -i -t ubuntu pwd
  664. The ``-volumes-from`` flag mounts all the defined volumes from the
  665. refrence containers. Containers can be specified by a comma seperated
  666. list or by repetitions of the ``-volumes-from`` argument. The container
  667. id may be optionally suffixed with ``:ro`` or ``:rw`` to mount the volumes in
  668. read-only or read-write mode, respectively. By default, the volumes are mounted
  669. in the same mode (rw or ro) as the reference container.
  670. .. _cli_save:
  671. ``save``
  672. ---------
  673. ::
  674. Usage: docker save image > repository.tar
  675. Streams a tarred repository to the standard output stream.
  676. Contains all parent layers, and all tags + versions.
  677. .. _cli_search:
  678. ``search``
  679. ----------
  680. ::
  681. Usage: docker search TERM
  682. Search the docker index for images
  683. -notrunc=false: Don't truncate output
  684. -stars=0: Only displays with at least xxx stars
  685. -trusted=false: Only show trusted builds
  686. .. _cli_start:
  687. ``start``
  688. ---------
  689. ::
  690. Usage: docker start [OPTIONS] NAME
  691. Start a stopped container
  692. -a=false: Attach container's stdout/stderr and forward all signals to the process
  693. -i=false: Attach container's stdin
  694. .. _cli_stop:
  695. ``stop``
  696. --------
  697. ::
  698. Usage: docker stop [OPTIONS] CONTAINER [CONTAINER...]
  699. Stop a running container (Send SIGTERM, and then SIGKILL after grace period)
  700. -t=10: Number of seconds to wait for the container to stop before killing it.
  701. The main process inside the container will receive SIGTERM, and after a grace period, SIGKILL
  702. .. _cli_tag:
  703. ``tag``
  704. -------
  705. ::
  706. Usage: docker tag [OPTIONS] IMAGE REPOSITORY[:TAG]
  707. Tag an image into a repository
  708. -f=false: Force
  709. .. _cli_top:
  710. ``top``
  711. -------
  712. ::
  713. Usage: docker top CONTAINER [ps OPTIONS]
  714. Lookup the running processes of a container
  715. .. _cli_version:
  716. ``version``
  717. -----------
  718. Show the version of the docker client, daemon, and latest released version.
  719. .. _cli_wait:
  720. ``wait``
  721. --------
  722. ::
  723. Usage: docker wait [OPTIONS] NAME
  724. Block until a container stops, then print its exit code.