cli.rst 35 KB

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