cli.rst 32 KB

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