cli.rst 38 KB

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