cli.rst 27 KB

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