cli.rst 38 KB

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