cli.rst 39 KB

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