cli.rst 26 KB

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