cli.rst 35 KB

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