cli.rst 38 KB

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