cli.rst 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082
  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. $ 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 SIZE
  175. SvenDowideit/testimage version3 f5283438590d 16 seconds ago 204.2 MB (virtual 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 SIZE
  347. <none> <none> 77af4d6b9913 19 hours ago 30.53 MB (virtual 1.089 GB)
  348. committest latest b6fa739cedf5 19 hours ago 30.53 MB (virtual 1.089 GB)
  349. <none> <none> 78a85c484f71 19 hours ago 30.53 MB (virtual 1.089 GB)
  350. docker latest 30557a29d5ab 20 hours ago 30.53 MB (virtual 1.089 GB)
  351. <none> <none> 0124422dd9f9 20 hours ago 30.53 MB (virtual 1.089 GB)
  352. <none> <none> 18ad6fad3402 22 hours ago 23.68 MB (virtual 1.082 GB)
  353. <none> <none> f9f1e26352f0 23 hours ago 30.46 MB (virtual 1.089 GB)
  354. tryout latest 2629d1fa0b81 23 hours ago 16.4 kB (virtual 131.5 MB)
  355. <none> <none> 5ed6274db6ce 24 hours ago 30.44 MB (virtual 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 SIZE
  361. <none> <none> 77af4d6b9913e693e8d0b4b294fa62ade6054e6b2f1ffb617ac955dd63fb0182 19 hours ago 30.53 MB (virtual 1.089 GB)
  362. committest latest b6fa739cedf5ea12a620a439402b6004d057da800f91c7524b5086a5e4749c9f 19 hours ago 30.53 MB (virtual 1.089 GB)
  363. <none> <none> 78a85c484f71509adeaace20e72e941f6bdd2b25b4c75da8693efd9f61a37921 19 hours ago 30.53 MB (virtual 1.089 GB)
  364. docker latest 30557a29d5abc51e5f1d5b472e79b7e296f595abcf19fe6b9199dbbc809c6ff4 20 hours ago 30.53 MB (virtual 1.089 GB)
  365. <none> <none> 0124422dd9f9cf7ef15c0617cda3931ee68346455441d66ab8bdc5b05e9fdce5 20 hours ago 30.53 MB (virtual 1.089 GB)
  366. <none> <none> 18ad6fad340262ac2a636efd98a6d1f0ea775ae3d45240d3418466495a19a81b 22 hours ago 23.68 MB (virtual 1.082 GB)
  367. <none> <none> f9f1e26352f0a3ba6a0ff68167559f64f3e21ff7ada60366e2d44a04befd1d3a 23 hours ago 30.46 MB (virtual 1.089 GB)
  368. tryout latest 2629d1fa0b81b222fca63371ca16cbf6a0772d07759ff80e8d1369b926940074 23 hours ago 16.4 kB (virtual 131.5 MB)
  369. <none> <none> 5ed6274db6ceb2397844896966ea239290555e74ef307030ebb01ff91b1914df 24 hours ago 30.44 MB (virtual 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 a new filesystem image from the contents of a tarball
  407. At this time, the URL must start with ``http`` and point to a single
  408. file archive (.tar, .tar.gz, .tgz, .bzip, .tar.xz, .txz) containing a
  409. root filesystem. If you would like to import from a local directory or
  410. archive, you can use the ``-`` parameter to take the data from
  411. standard in.
  412. Examples
  413. ~~~~~~~~
  414. Import from a remote location
  415. .............................
  416. This will create a new untagged image.
  417. ``$ sudo docker import http://example.com/exampleimage.tgz``
  418. Import from a local file
  419. ........................
  420. Import to docker via pipe and standard in
  421. ``$ cat exampleimage.tgz | sudo docker import - exampleimagelocal:new``
  422. Import from a local directory
  423. .............................
  424. ``$ sudo tar -c . | docker import - exampleimagedir``
  425. Note the ``sudo`` in this example -- you must preserve the ownership
  426. of the files (especially root ownership) during the archiving with
  427. tar. If you are not root (or sudo) when you tar, then the ownerships
  428. might not get preserved.
  429. .. _cli_info:
  430. ``info``
  431. --------
  432. ::
  433. Usage: docker info
  434. Display system-wide information.
  435. .. code-block:: bash
  436. $ sudo docker info
  437. Containers: 292
  438. Images: 194
  439. Debug mode (server): false
  440. Debug mode (client): false
  441. Fds: 22
  442. Goroutines: 67
  443. LXC Version: 0.9.0
  444. EventsListeners: 115
  445. Kernel Version: 3.8.0-33-generic
  446. WARNING: No swap limit support
  447. .. _cli_insert:
  448. ``insert``
  449. ----------
  450. ::
  451. Usage: docker insert IMAGE URL PATH
  452. Insert a file from URL in the IMAGE at PATH
  453. Use the specified IMAGE as the parent for a new image which adds a
  454. :ref:`layer <layer_def>` containing the new file. ``insert`` does not modify
  455. the original image, and the new image has the contents of the parent image,
  456. plus the new file.
  457. Examples
  458. ~~~~~~~~
  459. Insert file from github
  460. .......................
  461. .. code-block:: bash
  462. $ sudo docker insert 8283e18b24bc https://raw.github.com/metalivedev/django/master/postinstall /tmp/postinstall.sh
  463. 06fd35556d7b
  464. .. _cli_inspect:
  465. ``inspect``
  466. -----------
  467. ::
  468. Usage: docker inspect [OPTIONS] CONTAINER
  469. Return low-level information on a container
  470. .. _cli_kill:
  471. ``kill``
  472. --------
  473. ::
  474. Usage: docker kill CONTAINER [CONTAINER...]
  475. Kill a running container (Send SIGKILL)
  476. The main process inside the container will be sent SIGKILL.
  477. Known Issues (kill)
  478. ~~~~~~~~~~~~~~~~~~~
  479. * :issue:`197` indicates that ``docker kill`` may leave directories
  480. behind and make it difficult to remove the container.
  481. .. _cli_load:
  482. ``load``
  483. --------
  484. ::
  485. Usage: docker load < repository.tar
  486. Loads a tarred repository from the standard input stream.
  487. Restores both images and tags.
  488. .. _cli_login:
  489. ``login``
  490. ---------
  491. ::
  492. Usage: docker login [OPTIONS] [SERVER]
  493. Register or Login to the docker registry server
  494. -e="": email
  495. -p="": password
  496. -u="": username
  497. If you want to login to a private registry you can
  498. specify this by adding the server name.
  499. example:
  500. docker login localhost:8080
  501. .. _cli_logs:
  502. ``logs``
  503. --------
  504. ::
  505. Usage: docker logs [OPTIONS] CONTAINER
  506. Fetch the logs of a container
  507. .. _cli_port:
  508. ``port``
  509. --------
  510. ::
  511. Usage: docker port [OPTIONS] CONTAINER PRIVATE_PORT
  512. Lookup the public-facing port which is NAT-ed to PRIVATE_PORT
  513. .. _cli_ps:
  514. ``ps``
  515. ------
  516. ::
  517. Usage: docker ps [OPTIONS]
  518. List containers
  519. -a=false: Show all containers. Only running containers are shown by default.
  520. -notrunc=false: Don't truncate output
  521. -q=false: Only display numeric IDs
  522. .. _cli_pull:
  523. ``pull``
  524. --------
  525. ::
  526. Usage: docker pull NAME
  527. Pull an image or a repository from the registry
  528. .. _cli_push:
  529. ``push``
  530. --------
  531. ::
  532. Usage: docker push NAME
  533. Push an image or a repository to the registry
  534. .. _cli_restart:
  535. ``restart``
  536. -----------
  537. ::
  538. Usage: docker restart [OPTIONS] NAME
  539. Restart a running container
  540. .. _cli_rm:
  541. ``rm``
  542. ------
  543. ::
  544. Usage: docker rm [OPTIONS] CONTAINER
  545. Remove one or more containers
  546. -link="": Remove the link instead of the actual container
  547. Known Issues (rm)
  548. ~~~~~~~~~~~~~~~~~
  549. * :issue:`197` indicates that ``docker kill`` may leave directories
  550. behind and make it difficult to remove the container.
  551. Examples:
  552. ~~~~~~~~~
  553. .. code-block:: bash
  554. $ docker rm /redis
  555. /redis
  556. This will remove the container referenced under the link ``/redis``.
  557. .. code-block:: bash
  558. $ docker rm -link /webapp/redis
  559. /webapp/redis
  560. This will remove the underlying link between ``/webapp`` and the ``/redis`` containers removing all
  561. network communication.
  562. .. code-block:: bash
  563. $ docker rm `docker ps -a -q`
  564. This command will delete all stopped containers. The command ``docker ps -a -q`` will return all
  565. existing container IDs and pass them to the ``rm`` command which will delete them. Any running
  566. containers will not be deleted.
  567. .. _cli_rmi:
  568. ``rmi``
  569. -------
  570. ::
  571. Usage: docker rmi IMAGE [IMAGE...]
  572. Remove one or more images
  573. .. _cli_run:
  574. ``run``
  575. -------
  576. ::
  577. Usage: docker run [OPTIONS] IMAGE[:TAG] [COMMAND] [ARG...]
  578. Run a command in a new container
  579. -a=map[]: Attach to stdin, stdout or stderr
  580. -c=0: CPU shares (relative weight)
  581. -cidfile="": Write the container ID to the file
  582. -d=false: Detached mode: Run container in the background, print new container id
  583. -e=[]: Set environment variables
  584. -h="": Container host name
  585. -i=false: Keep stdin open even if not attached
  586. -privileged=false: Give extended privileges to this container
  587. -m="": Memory limit (format: <number><optional unit>, where unit = b, k, m or g)
  588. -n=true: Enable networking for this container
  589. -p=[]: Map a network port to the container
  590. -rm=false: Automatically remove the container when it exits (incompatible with -d)
  591. -t=false: Allocate a pseudo-tty
  592. -u="": Username or UID
  593. -dns=[]: Set custom dns servers for the container
  594. -v=[]: Create a bind mount with: [host-dir]:[container-dir]:[rw|ro]. If "container-dir" is missing, then docker creates a new volume.
  595. -volumes-from="": Mount all volumes from the given container(s)
  596. -entrypoint="": Overwrite the default entrypoint set by the image
  597. -w="": Working directory inside the container
  598. -lxc-conf=[]: Add custom lxc options -lxc-conf="lxc.cgroup.cpuset.cpus = 0,1"
  599. -sig-proxy=true: Proxify all received signal to the process (even in non-tty mode)
  600. -expose=[]: Expose a port from the container without publishing it to your host
  601. -link="": Add link to another container (name:alias)
  602. -name="": Assign the specified name to the container. If no name is specific docker will generate a random name
  603. -P=false: Publish all exposed ports to the host interfaces
  604. Known Issues (run -volumes-from)
  605. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  606. * :issue:`2702`: "lxc-start: Permission denied - failed to mount"
  607. could indicate a permissions problem with AppArmor. Please see the
  608. issue for a workaround.
  609. Examples:
  610. ~~~~~~~~~
  611. .. code-block:: bash
  612. sudo docker run -cidfile /tmp/docker_test.cid ubuntu echo "test"
  613. This will create a container and print "test" to the console. The
  614. ``cidfile`` flag makes docker attempt to create a new file and write the
  615. container ID to it. If the file exists already, docker will return an
  616. error. Docker will close this file when docker run exits.
  617. .. code-block:: bash
  618. docker run mount -t tmpfs none /var/spool/squid
  619. This will *not* work, because by default, most potentially dangerous
  620. kernel capabilities are dropped; including ``cap_sys_admin`` (which is
  621. required to mount filesystems). However, the ``-privileged`` flag will
  622. allow it to run:
  623. .. code-block:: bash
  624. docker run -privileged mount -t tmpfs none /var/spool/squid
  625. The ``-privileged`` flag gives *all* capabilities to the container,
  626. and it also lifts all the limitations enforced by the ``device``
  627. cgroup controller. In other words, the container can then do almost
  628. everything that the host can do. This flag exists to allow special
  629. use-cases, like running Docker within Docker.
  630. .. code-block:: bash
  631. docker run -w /path/to/dir/ -i -t ubuntu pwd
  632. The ``-w`` lets the command being executed inside directory given,
  633. here /path/to/dir/. If the path does not exists it is created inside the
  634. container.
  635. .. code-block:: bash
  636. docker run -v `pwd`:`pwd` -w `pwd` -i -t ubuntu pwd
  637. The ``-v`` flag mounts the current working directory into the container.
  638. The ``-w`` lets the command being executed inside the current
  639. working directory, by changing into the directory to the value
  640. returned by ``pwd``. So this combination executes the command
  641. using the container, but inside the current working directory.
  642. .. code-block:: bash
  643. docker run -p 127.0.0.1:80:8080 ubuntu bash
  644. This binds port ``8080`` of the container to port ``80`` on 127.0.0.1 of the
  645. host machine. :ref:`port_redirection` explains in detail how to manipulate ports
  646. in Docker.
  647. .. code-block:: bash
  648. docker run -expose 80 ubuntu bash
  649. This exposes port ``80`` of the container for use within a link without
  650. publishing the port to the host system's interfaces. :ref:`port_redirection`
  651. explains in detail how to manipulate ports in Docker.
  652. .. code-block:: bash
  653. docker run -name console -t -i ubuntu bash
  654. This will create and run a new container with the container name
  655. being ``console``.
  656. .. code-block:: bash
  657. docker run -link /redis:redis -name console ubuntu bash
  658. The ``-link`` flag will link the container named ``/redis`` into the
  659. newly created container with the alias ``redis``. The new container
  660. can access the network and environment of the redis container via
  661. environment variables. The ``-name`` flag will assign the name ``console``
  662. to the newly created container.
  663. .. code-block:: bash
  664. docker run -volumes-from 777f7dc92da7,ba8c0c54f0f2:ro -i -t ubuntu pwd
  665. The ``-volumes-from`` flag mounts all the defined volumes from the
  666. refrence containers. Containers can be specified by a comma seperated
  667. list or by repetitions of the ``-volumes-from`` argument. The container
  668. id may be optionally suffixed with ``:ro`` or ``:rw`` to mount the volumes in
  669. read-only or read-write mode, respectively. By default, the volumes are mounted
  670. in the same mode (rw or ro) as the reference container.
  671. .. _cli_save:
  672. ``save``
  673. ---------
  674. ::
  675. Usage: docker save image > repository.tar
  676. Streams a tarred repository to the standard output stream.
  677. Contains all parent layers, and all tags + versions.
  678. .. _cli_search:
  679. ``search``
  680. ----------
  681. ::
  682. Usage: docker search TERM
  683. Search the docker index for images
  684. -notrunc=false: Don't truncate output
  685. -stars=0: Only displays with at least xxx stars
  686. -trusted=false: Only show trusted builds
  687. .. _cli_start:
  688. ``start``
  689. ---------
  690. ::
  691. Usage: docker start [OPTIONS] NAME
  692. Start a stopped container
  693. -a=false: Attach container's stdout/stderr and forward all signals to the process
  694. -i=false: Attach container's stdin
  695. .. _cli_stop:
  696. ``stop``
  697. --------
  698. ::
  699. Usage: docker stop [OPTIONS] CONTAINER [CONTAINER...]
  700. Stop a running container (Send SIGTERM, and then SIGKILL after grace period)
  701. -t=10: Number of seconds to wait for the container to stop before killing it.
  702. The main process inside the container will receive SIGTERM, and after a grace period, SIGKILL
  703. .. _cli_tag:
  704. ``tag``
  705. -------
  706. ::
  707. Usage: docker tag [OPTIONS] IMAGE REPOSITORY[:TAG]
  708. Tag an image into a repository
  709. -f=false: Force
  710. .. _cli_top:
  711. ``top``
  712. -------
  713. ::
  714. Usage: docker top CONTAINER [ps OPTIONS]
  715. Lookup the running processes of a container
  716. .. _cli_version:
  717. ``version``
  718. -----------
  719. Show the version of the docker client, daemon, and latest released version.
  720. .. _cli_wait:
  721. ``wait``
  722. --------
  723. ::
  724. Usage: docker wait [OPTIONS] NAME
  725. Block until a container stops, then print its exit code.