cli.rst 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403
  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
  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=[127.0.0.1] is omitted for tcp or path=[/var/run/docker.sock] is omitted for unix sockets, default values are used.
  12. A self-sufficient runtime for linux containers.
  13. ...
  14. .. _cli_options:
  15. Option types
  16. ------------
  17. Single character commandline options can be combined, so rather than typing
  18. ``docker run -t -i --name test busybox sh``, you can write
  19. ``docker run -ti --name test busybox sh``.
  20. Boolean
  21. ~~~~~~~
  22. Boolean options look like ``-d=false``. The value you see is the
  23. default value which gets set if you do **not** use the boolean
  24. flag. If you do call ``run -d``, that sets the opposite boolean value,
  25. so in this case, ``true``, and so ``docker run -d`` **will** run in
  26. "detached" mode, in the background. Other boolean options are similar
  27. -- specifying them will set the value to the opposite of the default
  28. value.
  29. Multi
  30. ~~~~~
  31. Options like ``-a=[]`` indicate they can be specified multiple times::
  32. docker run -a stdin -a stdout -a stderr -i -t ubuntu /bin/bash
  33. Sometimes this can use a more complex value string, as for ``-v``::
  34. docker run -v /host:/container example/mysql
  35. Strings and Integers
  36. ~~~~~~~~~~~~~~~~~~~~
  37. Options like ``--name=""`` expect a string, and they can only be
  38. specified once. Options like ``-c=0`` expect an integer, and they can
  39. only be specified once.
  40. .. _cli_daemon:
  41. ``daemon``
  42. ----------
  43. ::
  44. Usage of docker:
  45. -D, --debug=false: Enable debug mode
  46. -H, --host=[]: Multiple tcp://host:port or unix://path/to/socket to bind in daemon mode, single connection otherwise. systemd socket activation can be used with fd://[socketfd].
  47. -G, --group="docker": Group to assign the unix socket specified by -H when running in daemon mode; use '' (the empty string) to disable setting of a group
  48. --api-enable-cors=false: Enable CORS headers in the remote API
  49. -b, --bridge="": Attach containers to a pre-existing network bridge; use 'none' to disable container networking
  50. -bip="": Use this CIDR notation address for the network bridge's IP, not compatible with -b
  51. -d, --daemon=false: Enable daemon mode
  52. --dns=[]: Force docker to use specific DNS servers
  53. --dns-search=[]: Force Docker to use specific DNS search domains
  54. -g, --graph="/var/lib/docker": Path to use as the root of the docker runtime
  55. --icc=true: Enable inter-container communication
  56. --ip="0.0.0.0": Default IP address to use when binding container ports
  57. --ip-forward=true: Enable net.ipv4.ip_forward
  58. --iptables=true: Enable Docker's addition of iptables rules
  59. -p, --pidfile="/var/run/docker.pid": Path to use for daemon PID file
  60. -r, --restart=true: Restart previously running containers
  61. -s, --storage-driver="": Force the docker runtime to use a specific storage driver
  62. -e, --exec-driver="native": Force the docker runtime to use a specific exec driver
  63. -v, --version=false: Print version information and quit
  64. --tls=false: Use TLS; implied by tls-verify flags
  65. --tlscacert="~/.docker/ca.pem": Trust only remotes providing a certificate signed by the CA given here
  66. --tlscert="~/.docker/cert.pem": Path to TLS certificate file
  67. --tlskey="~/.docker/key.pem": Path to TLS key file
  68. --tlsverify=false: Use TLS and verify the remote (daemon: verify client, client: verify daemon)
  69. --mtu=0: Set the containers network MTU; if no value is provided: default to the default route MTU or 1500 if no default route is available
  70. The Docker daemon is the persistent process that manages containers. Docker uses the same binary for both the
  71. daemon and client. To run the daemon you provide the ``-d`` flag.
  72. To force Docker to use devicemapper as the storage driver, use ``docker -d -s devicemapper``.
  73. To set the DNS server for all Docker containers, use ``docker -d --dns 8.8.8.8``.
  74. To set the DNS search domain for all Docker containers, use ``docker -d --dns-search example.com``.
  75. To run the daemon with debug output, use ``docker -d -D``.
  76. To use lxc as the execution driver, use ``docker -d -e lxc``.
  77. The docker client will also honor the ``DOCKER_HOST`` environment variable to set
  78. the ``-H`` flag for the client.
  79. ::
  80. docker -H tcp://0.0.0.0:4243 ps
  81. # or
  82. export DOCKER_HOST="tcp://0.0.0.0:4243"
  83. docker ps
  84. # both are equal
  85. To run the daemon with `systemd socket activation <http://0pointer.de/blog/projects/socket-activation.html>`_, use ``docker -d -H fd://``.
  86. Using ``fd://`` will work perfectly for most setups but you can also specify individual sockets too ``docker -d -H fd://3``.
  87. If the specified socket activated files aren't found then docker will exit.
  88. You can find examples of using systemd socket activation with docker and systemd in the `docker source tree <https://github.com/dotcloud/docker/blob/master/contrib/init/systemd/socket-activation/>`_.
  89. Docker supports softlinks for the Docker data directory (``/var/lib/docker``) and for ``/tmp``.
  90. TMPDIR and the data directory can be set like this:
  91. ::
  92. TMPDIR=/mnt/disk2/tmp /usr/local/bin/docker -d -D -g /var/lib/docker -H unix:// > /var/lib/boot2docker/docker.log 2>&1
  93. # or
  94. export TMPDIR=/mnt/disk2/tmp
  95. /usr/local/bin/docker -d -D -g /var/lib/docker -H unix:// > /var/lib/boot2docker/docker.log 2>&1
  96. .. _cli_attach:
  97. ``attach``
  98. ----------
  99. ::
  100. Usage: docker attach CONTAINER
  101. Attach to a running container.
  102. --no-stdin=false: Do not attach stdin
  103. --sig-proxy=true: Proxify all received signal to the process (even in non-tty mode)
  104. The ``attach`` command will allow you to view or interact with any
  105. running container, detached (``-d``) or interactive (``-i``). You can
  106. attach to the same container at the same time - screen sharing style,
  107. or quickly view the progress of your daemonized process.
  108. You can detach from the container again (and leave it running) with
  109. ``CTRL-C`` (for a quiet exit) or ``CTRL-\`` to get a stacktrace of
  110. the Docker client when it quits. When you detach from the container's
  111. process the exit code will be returned to the client.
  112. To stop a container, use ``docker stop``.
  113. To kill the container, use ``docker kill``.
  114. .. _cli_attach_examples:
  115. Examples:
  116. ~~~~~~~~~
  117. .. code-block:: bash
  118. $ ID=$(sudo docker run -d ubuntu /usr/bin/top -b)
  119. $ sudo docker attach $ID
  120. top - 02:05:52 up 3:05, 0 users, load average: 0.01, 0.02, 0.05
  121. Tasks: 1 total, 1 running, 0 sleeping, 0 stopped, 0 zombie
  122. 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
  123. Mem: 373572k total, 355560k used, 18012k free, 27872k buffers
  124. Swap: 786428k total, 0k used, 786428k free, 221740k cached
  125. PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
  126. 1 root 20 0 17200 1116 912 R 0 0.3 0:00.03 top
  127. top - 02:05:55 up 3:05, 0 users, load average: 0.01, 0.02, 0.05
  128. Tasks: 1 total, 1 running, 0 sleeping, 0 stopped, 0 zombie
  129. 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
  130. Mem: 373572k total, 355244k used, 18328k free, 27872k buffers
  131. Swap: 786428k total, 0k used, 786428k free, 221776k cached
  132. PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
  133. 1 root 20 0 17208 1144 932 R 0 0.3 0:00.03 top
  134. top - 02:05:58 up 3:06, 0 users, load average: 0.01, 0.02, 0.05
  135. Tasks: 1 total, 1 running, 0 sleeping, 0 stopped, 0 zombie
  136. 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
  137. Mem: 373572k total, 355780k used, 17792k free, 27880k buffers
  138. Swap: 786428k total, 0k used, 786428k free, 221776k cached
  139. PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
  140. 1 root 20 0 17208 1144 932 R 0 0.3 0:00.03 top
  141. ^C$
  142. $ sudo docker stop $ID
  143. .. _cli_build:
  144. ``build``
  145. ---------
  146. ::
  147. Usage: docker build [OPTIONS] PATH | URL | -
  148. Build a new container image from the source code at PATH
  149. -t, --tag="": Repository name (and optionally a tag) to be applied
  150. to the resulting image in case of success.
  151. -q, --quiet=false: Suppress the verbose output generated by the containers.
  152. --no-cache: Do not use the cache when building the image.
  153. --rm=true: Remove intermediate containers after a successful build
  154. Use this command to build Docker images from a ``Dockerfile`` and a "context".
  155. The files at ``PATH`` or ``URL`` are called the "context" of the build.
  156. The build process may refer to any of the files in the context, for example when
  157. using an :ref:`ADD <dockerfile_add>` instruction.
  158. When a single ``Dockerfile`` is given as ``URL``, then no context is set.
  159. When a Git repository is set as ``URL``, then the repository is used as the context.
  160. The Git repository is cloned with its submodules (`git clone --recursive`).
  161. A fresh git clone occurs in a temporary directory on your local host, and then this
  162. is sent to the Docker daemon as the context.
  163. This way, your local user credentials and vpn's etc can be used to access private repositories
  164. .. _cli_build_examples:
  165. .. seealso:: :ref:`dockerbuilder`.
  166. Examples:
  167. ~~~~~~~~~
  168. .. code-block:: bash
  169. $ sudo docker build .
  170. Uploading context 10240 bytes
  171. Step 1 : FROM busybox
  172. Pulling repository busybox
  173. ---> e9aa60c60128MB/2.284 MB (100%) endpoint: https://cdn-registry-1.docker.io/v1/
  174. Step 2 : RUN ls -lh /
  175. ---> Running in 9c9e81692ae9
  176. total 24
  177. drwxr-xr-x 2 root root 4.0K Mar 12 2013 bin
  178. drwxr-xr-x 5 root root 4.0K Oct 19 00:19 dev
  179. drwxr-xr-x 2 root root 4.0K Oct 19 00:19 etc
  180. drwxr-xr-x 2 root root 4.0K Nov 15 23:34 lib
  181. lrwxrwxrwx 1 root root 3 Mar 12 2013 lib64 -> lib
  182. dr-xr-xr-x 116 root root 0 Nov 15 23:34 proc
  183. lrwxrwxrwx 1 root root 3 Mar 12 2013 sbin -> bin
  184. dr-xr-xr-x 13 root root 0 Nov 15 23:34 sys
  185. drwxr-xr-x 2 root root 4.0K Mar 12 2013 tmp
  186. drwxr-xr-x 2 root root 4.0K Nov 15 23:34 usr
  187. ---> b35f4035db3f
  188. Step 3 : CMD echo Hello World
  189. ---> Running in 02071fceb21b
  190. ---> f52f38b7823e
  191. Successfully built f52f38b7823e
  192. Removing intermediate container 9c9e81692ae9
  193. Removing intermediate container 02071fceb21b
  194. This example specifies that the ``PATH`` is ``.``, and so all the files in
  195. the local directory get tar'd and sent to the Docker daemon. The ``PATH``
  196. specifies where to find the files for the "context" of the build on
  197. the Docker daemon. Remember that the daemon could be running on a
  198. remote machine and that no parsing of the ``Dockerfile`` happens at the
  199. client side (where you're running ``docker build``). That means that
  200. *all* the files at ``PATH`` get sent, not just the ones listed to
  201. :ref:`ADD <dockerfile_add>` in the ``Dockerfile``.
  202. The transfer of context from the local machine to the Docker daemon is
  203. what the ``docker`` client means when you see the "Uploading context"
  204. message.
  205. If you wish to keep the intermediate containers after the build is complete,
  206. you must use ``--rm=false``. This does not affect the build cache.
  207. .. code-block:: bash
  208. $ sudo docker build -t vieux/apache:2.0 .
  209. This will build like the previous example, but it will then tag the
  210. resulting image. The repository name will be ``vieux/apache`` and the
  211. tag will be ``2.0``
  212. .. code-block:: bash
  213. $ sudo docker build - < Dockerfile
  214. This will read a ``Dockerfile`` from *stdin* without context. Due to
  215. the lack of a context, no contents of any local directory will be sent
  216. to the ``docker`` daemon. Since there is no context, a ``Dockerfile``
  217. ``ADD`` only works if it refers to a remote URL.
  218. .. code-block:: bash
  219. $ sudo docker build github.com/creack/docker-firefox
  220. This will clone the GitHub repository and use the cloned repository as
  221. context. The ``Dockerfile`` at the root of the repository is used as
  222. ``Dockerfile``. Note that you can specify an arbitrary Git repository
  223. by using the ``git://`` schema.
  224. .. _cli_commit:
  225. ``commit``
  226. ----------
  227. ::
  228. Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
  229. Create a new image from a container's changes
  230. -m, --message="": Commit message
  231. -a, --author="": Author (eg. "John Hannibal Smith <hannibal@a-team.com>"
  232. It can be useful to commit a container's file changes or settings into a new image.
  233. This allows you debug a container by running an interactive shell, or to export
  234. a working dataset to another server.
  235. Generally, it is better to use Dockerfiles to manage your images in a documented
  236. and maintainable way.
  237. .. _cli_commit_examples:
  238. Commit an existing container
  239. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  240. .. code-block:: bash
  241. $ sudo docker ps
  242. ID IMAGE COMMAND CREATED STATUS PORTS
  243. c3f279d17e0a ubuntu:12.04 /bin/bash 7 days ago Up 25 hours
  244. 197387f1b436 ubuntu:12.04 /bin/bash 7 days ago Up 25 hours
  245. $ docker commit c3f279d17e0a SvenDowideit/testimage:version3
  246. f5283438590d
  247. $ docker images | head
  248. REPOSITORY TAG ID CREATED VIRTUAL SIZE
  249. SvenDowideit/testimage version3 f5283438590d 16 seconds ago 335.7 MB
  250. .. _cli_cp:
  251. ``cp``
  252. ------
  253. ::
  254. Usage: docker cp CONTAINER:PATH HOSTPATH
  255. Copy files/folders from the containers filesystem to the host
  256. path. Paths are relative to the root of the filesystem.
  257. .. code-block:: bash
  258. $ sudo docker cp 7bb0e258aefe:/etc/debian_version .
  259. $ sudo docker cp blue_frog:/etc/hosts .
  260. .. _cli_diff:
  261. ``diff``
  262. --------
  263. ::
  264. Usage: docker diff CONTAINER
  265. List the changed files and directories in a container's filesystem
  266. There are 3 events that are listed in the 'diff':
  267. 1. ```A``` - Add
  268. 2. ```D``` - Delete
  269. 3. ```C``` - Change
  270. For example:
  271. .. code-block:: bash
  272. $ sudo docker diff 7bb0e258aefe
  273. C /dev
  274. A /dev/kmsg
  275. C /etc
  276. A /etc/mtab
  277. A /go
  278. A /go/src
  279. A /go/src/github.com
  280. A /go/src/github.com/dotcloud
  281. A /go/src/github.com/dotcloud/docker
  282. A /go/src/github.com/dotcloud/docker/.git
  283. ....
  284. .. _cli_events:
  285. ``events``
  286. ----------
  287. ::
  288. Usage: docker events
  289. Get real time events from the server
  290. --since="": Show all events created since timestamp
  291. (either seconds since epoch, or date string as below)
  292. --until="": Show events created before timestamp
  293. (either seconds since epoch, or date string as below)
  294. .. _cli_events_example:
  295. Examples
  296. ~~~~~~~~
  297. You'll need two shells for this example.
  298. Shell 1: Listening for events
  299. .............................
  300. .. code-block:: bash
  301. $ sudo docker events
  302. Shell 2: Start and Stop a Container
  303. ...................................
  304. .. code-block:: bash
  305. $ sudo docker start 4386fb97867d
  306. $ sudo docker stop 4386fb97867d
  307. Shell 1: (Again .. now showing events)
  308. ......................................
  309. .. code-block:: bash
  310. [2013-09-03 15:49:26 +0200 CEST] 4386fb97867d: (from 12de384bfb10) start
  311. [2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) die
  312. [2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) stop
  313. Show events in the past from a specified time
  314. .............................................
  315. .. code-block:: bash
  316. $ sudo docker events --since 1378216169
  317. [2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) die
  318. [2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) stop
  319. $ sudo docker events --since '2013-09-03'
  320. [2013-09-03 15:49:26 +0200 CEST] 4386fb97867d: (from 12de384bfb10) start
  321. [2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) die
  322. [2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) stop
  323. $ sudo docker events --since '2013-09-03 15:49:29 +0200 CEST'
  324. [2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) die
  325. [2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) stop
  326. .. _cli_export:
  327. ``export``
  328. ----------
  329. ::
  330. Usage: docker export CONTAINER
  331. Export the contents of a filesystem as a tar archive to STDOUT
  332. For example:
  333. .. code-block:: bash
  334. $ sudo docker export red_panda > latest.tar
  335. .. _cli_history:
  336. ``history``
  337. -----------
  338. ::
  339. Usage: docker history [OPTIONS] IMAGE
  340. Show the history of an image
  341. --no-trunc=false: Don't truncate output
  342. -q, --quiet=false: Only show numeric IDs
  343. To see how the ``docker:latest`` image was built:
  344. .. code-block:: bash
  345. $ docker history docker
  346. IMAGE CREATED CREATED BY SIZE
  347. 3e23a5875458790b7a806f95f7ec0d0b2a5c1659bfc899c89f939f6d5b8f7094 8 days ago /bin/sh -c #(nop) ENV LC_ALL=C.UTF-8 0 B
  348. 8578938dd17054dce7993d21de79e96a037400e8d28e15e7290fea4f65128a36 8 days ago /bin/sh -c dpkg-reconfigure locales && locale-gen C.UTF-8 && /usr/sbin/update-locale LANG=C.UTF-8 1.245 MB
  349. be51b77efb42f67a5e96437b3e102f81e0a1399038f77bf28cea0ed23a65cf60 8 days ago /bin/sh -c apt-get update && apt-get install -y git libxml2-dev python build-essential make gcc python-dev locales python-pip 338.3 MB
  350. 4b137612be55ca69776c7f30c2d2dd0aa2e7d72059820abf3e25b629f887a084 6 weeks ago /bin/sh -c #(nop) ADD jessie.tar.xz in / 121 MB
  351. 750d58736b4b6cc0f9a9abe8f258cef269e3e9dceced1146503522be9f985ada 6 weeks ago /bin/sh -c #(nop) MAINTAINER Tianon Gravi <admwiggin@gmail.com> - mkimage-debootstrap.sh -t jessie.tar.xz jessie http://http.debian.net/debian 0 B
  352. 511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158 9 months ago 0 B
  353. .. _cli_images:
  354. ``images``
  355. ----------
  356. ::
  357. Usage: docker images [OPTIONS] [NAME]
  358. List images
  359. -a, --all=false: Show all images (by default filter out the intermediate image layers)
  360. --no-trunc=false: Don't truncate output
  361. -q, --quiet=false: Only show numeric IDs
  362. The default ``docker images`` will show all top level images, their repository
  363. and tags, and their virtual size.
  364. Docker images have intermediate layers that increase reuseability, decrease
  365. disk usage, and speed up ``docker build`` by allowing each step to be cached.
  366. These intermediate layers are not shown by default.
  367. Listing the most recently created images
  368. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  369. .. code-block:: bash
  370. $ sudo docker images | head
  371. REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
  372. <none> <none> 77af4d6b9913 19 hours ago 1.089 GB
  373. committest latest b6fa739cedf5 19 hours ago 1.089 GB
  374. <none> <none> 78a85c484f71 19 hours ago 1.089 GB
  375. docker latest 30557a29d5ab 20 hours ago 1.089 GB
  376. <none> <none> 0124422dd9f9 20 hours ago 1.089 GB
  377. <none> <none> 18ad6fad3402 22 hours ago 1.082 GB
  378. <none> <none> f9f1e26352f0 23 hours ago 1.089 GB
  379. tryout latest 2629d1fa0b81 23 hours ago 131.5 MB
  380. <none> <none> 5ed6274db6ce 24 hours ago 1.089 GB
  381. Listing the full length image IDs
  382. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  383. .. code-block:: bash
  384. $ sudo docker images --no-trunc | head
  385. REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
  386. <none> <none> 77af4d6b9913e693e8d0b4b294fa62ade6054e6b2f1ffb617ac955dd63fb0182 19 hours ago 1.089 GB
  387. committest latest b6fa739cedf5ea12a620a439402b6004d057da800f91c7524b5086a5e4749c9f 19 hours ago 1.089 GB
  388. <none> <none> 78a85c484f71509adeaace20e72e941f6bdd2b25b4c75da8693efd9f61a37921 19 hours ago 1.089 GB
  389. docker latest 30557a29d5abc51e5f1d5b472e79b7e296f595abcf19fe6b9199dbbc809c6ff4 20 hours ago 1.089 GB
  390. <none> <none> 0124422dd9f9cf7ef15c0617cda3931ee68346455441d66ab8bdc5b05e9fdce5 20 hours ago 1.089 GB
  391. <none> <none> 18ad6fad340262ac2a636efd98a6d1f0ea775ae3d45240d3418466495a19a81b 22 hours ago 1.082 GB
  392. <none> <none> f9f1e26352f0a3ba6a0ff68167559f64f3e21ff7ada60366e2d44a04befd1d3a 23 hours ago 1.089 GB
  393. tryout latest 2629d1fa0b81b222fca63371ca16cbf6a0772d07759ff80e8d1369b926940074 23 hours ago 131.5 MB
  394. <none> <none> 5ed6274db6ceb2397844896966ea239290555e74ef307030ebb01ff91b1914df 24 hours ago 1.089 GB
  395. .. _cli_import:
  396. ``import``
  397. ----------
  398. ::
  399. Usage: docker import URL|- [REPOSITORY[:TAG]]
  400. Create an empty filesystem image and import the contents of the tarball
  401. (.tar, .tar.gz, .tgz, .bzip, .tar.xz, .txz) into it, then optionally tag it.
  402. URLs must start with ``http`` and point to a single
  403. file archive (.tar, .tar.gz, .tgz, .bzip, .tar.xz, or .txz) containing a
  404. root filesystem. If you would like to import from a local directory or
  405. archive, you can use the ``-`` parameter to take the data from *stdin*.
  406. Examples
  407. ~~~~~~~~
  408. Import from a remote location
  409. .............................
  410. This will create a new untagged image.
  411. .. code-block:: bash
  412. $ sudo docker import http://example.com/exampleimage.tgz
  413. Import from a local file
  414. ........................
  415. Import to docker via pipe and *stdin*.
  416. .. code-block:: bash
  417. $ cat exampleimage.tgz | sudo docker import - exampleimagelocal:new
  418. Import from a local directory
  419. .............................
  420. .. code-block:: bash
  421. $ sudo tar -c . | docker import - exampleimagedir
  422. Note the ``sudo`` in this example -- you must preserve the ownership of the
  423. files (especially root ownership) during the archiving with tar. If you are not
  424. root (or the sudo command) when you tar, then the ownerships might not get
  425. preserved.
  426. .. _cli_info:
  427. ``info``
  428. --------
  429. ::
  430. Usage: docker info
  431. Display system-wide information.
  432. .. code-block:: bash
  433. $ sudo docker info
  434. Containers: 292
  435. Images: 194
  436. Debug mode (server): false
  437. Debug mode (client): false
  438. Fds: 22
  439. Goroutines: 67
  440. LXC Version: 0.9.0
  441. EventsListeners: 115
  442. Kernel Version: 3.8.0-33-generic
  443. WARNING: No swap limit support
  444. When sending issue reports, please use ``docker version`` and ``docker info`` to
  445. ensure we know how your setup is configured.
  446. .. _cli_inspect:
  447. ``inspect``
  448. -----------
  449. ::
  450. Usage: docker inspect CONTAINER|IMAGE [CONTAINER|IMAGE...]
  451. Return low-level information on a container/image
  452. -f, --format="": Format the output using the given go template.
  453. By default, this will render all results in a JSON array. If a format
  454. is specified, the given template will be executed for each result.
  455. Go's `text/template <http://golang.org/pkg/text/template/>`_ package
  456. describes all the details of the format.
  457. Examples
  458. ~~~~~~~~
  459. Get an instance's IP Address
  460. ............................
  461. For the most part, you can pick out any field from the JSON in a
  462. fairly straightforward manner.
  463. .. code-block:: bash
  464. $ sudo docker inspect --format='{{.NetworkSettings.IPAddress}}' $INSTANCE_ID
  465. List All Port Bindings
  466. ......................
  467. One can loop over arrays and maps in the results to produce simple
  468. text output:
  469. .. code-block:: bash
  470. $ sudo docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' $INSTANCE_ID
  471. Find a Specific Port Mapping
  472. ............................
  473. The ``.Field`` syntax doesn't work when the field name begins with a
  474. number, but the template language's ``index`` function does. The
  475. ``.NetworkSettings.Ports`` section contains a map of the internal port
  476. mappings to a list of external address/port objects, so to grab just
  477. the numeric public port, you use ``index`` to find the specific port
  478. map, and then ``index`` 0 contains first object inside of that. Then
  479. we ask for the ``HostPort`` field to get the public address.
  480. .. code-block:: bash
  481. $ sudo docker inspect --format='{{(index (index .NetworkSettings.Ports "8787/tcp") 0).HostPort}}' $INSTANCE_ID
  482. Get config
  483. ..........
  484. The ``.Field`` syntax doesn't work when the field contains JSON data,
  485. but the template language's custom ``json`` function does. The ``.config``
  486. section contains complex json object, so to grab it as JSON, you use ``json``
  487. to convert config object into JSON
  488. .. code-block:: bash
  489. $ sudo docker inspect --format='{{json .config}}' $INSTANCE_ID
  490. .. _cli_kill:
  491. ``kill``
  492. --------
  493. ::
  494. Usage: docker kill [OPTIONS] CONTAINER [CONTAINER...]
  495. Kill a running container (send SIGKILL, or specified signal)
  496. -s, --signal="KILL": Signal to send to the container
  497. The main process inside the container will be sent SIGKILL, or any signal specified with option ``--signal``.
  498. Known Issues (kill)
  499. ~~~~~~~~~~~~~~~~~~~
  500. * :issue:`197` indicates that ``docker kill`` may leave directories
  501. behind and make it difficult to remove the container.
  502. * :issue:`3844` lxc 1.0.0 beta3 removed ``lcx-kill`` which is used by Docker versions before 0.8.0;
  503. see the issue for a workaround.
  504. .. _cli_load:
  505. ``load``
  506. --------
  507. ::
  508. Usage: docker load
  509. Load an image from a tar archive on STDIN
  510. -i, --input="": Read from a tar archive file, instead of STDIN
  511. Loads a tarred repository from a file or the standard input stream.
  512. Restores both images and tags.
  513. .. code-block:: bash
  514. $ sudo docker images
  515. REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
  516. $ sudo docker load < busybox.tar
  517. $ sudo docker images
  518. REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
  519. busybox latest 769b9341d937 7 weeks ago 2.489 MB
  520. $ sudo docker load --input fedora.tar
  521. $ sudo docker images
  522. REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
  523. busybox latest 769b9341d937 7 weeks ago 2.489 MB
  524. fedora rawhide 0d20aec6529d 7 weeks ago 387 MB
  525. fedora 20 58394af37342 7 weeks ago 385.5 MB
  526. fedora heisenbug 58394af37342 7 weeks ago 385.5 MB
  527. fedora latest 58394af37342 7 weeks ago 385.5 MB
  528. .. _cli_login:
  529. ``login``
  530. ---------
  531. ::
  532. Usage: docker login [OPTIONS] [SERVER]
  533. Register or Login to the docker registry server
  534. -e, --email="": Email
  535. -p, --password="": Password
  536. -u, --username="": Username
  537. If you want to login to a private registry you can
  538. specify this by adding the server name.
  539. example:
  540. docker login localhost:8080
  541. .. _cli_logs:
  542. ``logs``
  543. --------
  544. ::
  545. Usage: docker logs [OPTIONS] CONTAINER
  546. Fetch the logs of a container
  547. -f, --follow=false: Follow log output
  548. The ``docker logs`` command batch-retrieves all logs present at the time of execution.
  549. The ``docker logs --follow`` command combines ``docker logs`` and ``docker attach``:
  550. it will first return all logs from the beginning and then continue streaming
  551. new output from the container's stdout and stderr.
  552. .. _cli_port:
  553. ``port``
  554. --------
  555. ::
  556. Usage: docker port [OPTIONS] CONTAINER PRIVATE_PORT
  557. Lookup the public-facing port which is NAT-ed to PRIVATE_PORT
  558. .. _cli_ps:
  559. ``ps``
  560. ------
  561. ::
  562. Usage: docker ps [OPTIONS]
  563. List containers
  564. -a, --all=false: Show all containers. Only running containers are shown by default.
  565. --before="": Show only container created before Id or Name, include non-running ones.
  566. -l, --latest=false: Show only the latest created container, include non-running ones.
  567. -n=-1: Show n last created containers, include non-running ones.
  568. --no-trunc=false: Don't truncate output
  569. -q, --quiet=false: Only display numeric IDs
  570. -s, --size=false: Display sizes, not to be used with -q
  571. --since="": Show only containers created since Id or Name, include non-running ones.
  572. Running ``docker ps`` showing 2 linked containers.
  573. .. code-block:: bash
  574. $ docker ps
  575. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  576. 4c01db0b339c ubuntu:12.04 bash 17 seconds ago Up 16 seconds webapp
  577. d7886598dbe2 crosbymichael/redis:latest /redis-server --dir 33 minutes ago Up 33 minutes 6379/tcp redis,webapp/db
  578. ``docker ps`` will show only running containers by default. To see all containers: ``docker ps -a``
  579. .. _cli_pull:
  580. ``pull``
  581. --------
  582. ::
  583. Usage: docker pull NAME[:TAG]
  584. Pull an image or a repository from the registry
  585. Most of your images will be created on top of a base image from the
  586. <Docker Index>(https://index.docker.io).
  587. The Docker Index contains many pre-built images that you can ``pull`` and try
  588. without needing to define and configure your own.
  589. To download a particular image, or set of images (i.e., a repository),
  590. use ``docker pull``:
  591. .. code-block:: bash
  592. $ docker pull debian
  593. # will pull all the images in the debian repository
  594. $ docker pull debian:testing
  595. # will pull only the image named debian:testing and any intermediate layers
  596. # it is based on. (typically the empty `scratch` image, a MAINTAINERs layer,
  597. # and the un-tared base.
  598. .. _cli_push:
  599. ``push``
  600. --------
  601. ::
  602. Usage: docker push NAME[:TAG]
  603. Push an image or a repository to the registry
  604. Use ``docker push`` to share your images on public or private registries.
  605. .. _cli_restart:
  606. ``restart``
  607. -----------
  608. ::
  609. Usage: docker restart [OPTIONS] NAME
  610. Restart a running container
  611. -t, --time=10: Number of seconds to try to stop for before killing the container. Once killed it will then be restarted. Default=10
  612. .. _cli_rm:
  613. ``rm``
  614. ------
  615. ::
  616. Usage: docker rm [OPTIONS] CONTAINER
  617. Remove one or more containers
  618. -l, --link="": Remove the link instead of the actual container
  619. -f, --force=false: Force removal of running container
  620. -v, --volumes=false: Remove the volumes associated to the container
  621. Known Issues (rm)
  622. ~~~~~~~~~~~~~~~~~
  623. * :issue:`197` indicates that ``docker kill`` may leave directories
  624. behind and make it difficult to remove the container.
  625. Examples:
  626. ~~~~~~~~~
  627. .. code-block:: bash
  628. $ sudo docker rm /redis
  629. /redis
  630. This will remove the container referenced under the link ``/redis``.
  631. .. code-block:: bash
  632. $ sudo docker rm --link /webapp/redis
  633. /webapp/redis
  634. This will remove the underlying link between ``/webapp`` and the ``/redis`` containers removing all
  635. network communication.
  636. .. code-block:: bash
  637. $ sudo docker rm $(docker ps -a -q)
  638. This command will delete all stopped containers. The command ``docker ps -a -q`` will return all
  639. existing container IDs and pass them to the ``rm`` command which will delete them. Any running
  640. containers will not be deleted.
  641. .. _cli_rmi:
  642. ``rmi``
  643. -------
  644. ::
  645. Usage: docker rmi IMAGE [IMAGE...]
  646. Remove one or more images
  647. -f, --force=false: Force
  648. --no-prune=false: Do not delete untagged parents
  649. Removing tagged images
  650. ~~~~~~~~~~~~~~~~~~~~~~
  651. Images can be removed either by their short or long ID's, or their image names.
  652. If an image has more than one name, each of them needs to be removed before the
  653. image is removed.
  654. .. code-block:: bash
  655. $ sudo docker images
  656. REPOSITORY TAG IMAGE ID CREATED SIZE
  657. test1 latest fd484f19954f 23 seconds ago 7 B (virtual 4.964 MB)
  658. test latest fd484f19954f 23 seconds ago 7 B (virtual 4.964 MB)
  659. test2 latest fd484f19954f 23 seconds ago 7 B (virtual 4.964 MB)
  660. $ sudo docker rmi fd484f19954f
  661. Error: Conflict, cannot delete image fd484f19954f because it is tagged in multiple repositories
  662. 2013/12/11 05:47:16 Error: failed to remove one or more images
  663. $ sudo docker rmi test1
  664. Untagged: fd484f19954f4920da7ff372b5067f5b7ddb2fd3830cecd17b96ea9e286ba5b8
  665. $ sudo docker rmi test2
  666. Untagged: fd484f19954f4920da7ff372b5067f5b7ddb2fd3830cecd17b96ea9e286ba5b8
  667. $ sudo docker images
  668. REPOSITORY TAG IMAGE ID CREATED SIZE
  669. test1 latest fd484f19954f 23 seconds ago 7 B (virtual 4.964 MB)
  670. $ sudo docker rmi test
  671. Untagged: fd484f19954f4920da7ff372b5067f5b7ddb2fd3830cecd17b96ea9e286ba5b8
  672. Deleted: fd484f19954f4920da7ff372b5067f5b7ddb2fd3830cecd17b96ea9e286ba5b8
  673. .. _cli_run:
  674. ``run``
  675. -------
  676. ::
  677. Usage: docker run [OPTIONS] IMAGE[:TAG] [COMMAND] [ARG...]
  678. Run a command in a new container
  679. -a, --attach=map[]: Attach to stdin, stdout or stderr
  680. -c, --cpu-shares=0: CPU shares (relative weight)
  681. --cidfile="": Write the container ID to the file
  682. -d, --detach=false: Detached mode: Run container in the background, print new container id
  683. -e, --env=[]: Set environment variables
  684. --env-file="": Read in a line delimited file of ENV variables
  685. -h, --hostname="": Container host name
  686. -i, --interactive=false: Keep stdin open even if not attached
  687. --privileged=false: Give extended privileges to this container
  688. -m, --memory="": Memory limit (format: <number><optional unit>, where unit = b, k, m or g)
  689. -n, --networking=true: Enable networking for this container
  690. -p, --publish=[]: Map a network port to the container
  691. --rm=false: Automatically remove the container when it exits (incompatible with -d)
  692. -t, --tty=false: Allocate a pseudo-tty
  693. -u, --user="": Username or UID
  694. --dns=[]: Set custom dns servers for the container
  695. --dns-search=[]: Set custom DNS search domains for the container
  696. -v, --volume=[]: Create a bind mount to a directory or file with: [host-path]:[container-path]:[rw|ro]. If a directory "container-path" is missing, then docker creates a new volume.
  697. --volumes-from="": Mount all volumes from the given container(s)
  698. --entrypoint="": Overwrite the default entrypoint set by the image
  699. -w, --workdir="": Working directory inside the container
  700. --lxc-conf=[]: (lxc exec-driver only) Add custom lxc options --lxc-conf="lxc.cgroup.cpuset.cpus = 0,1"
  701. --sig-proxy=true: Proxify all received signal to the process (even in non-tty mode)
  702. --expose=[]: Expose a port from the container without publishing it to your host
  703. --link="": Add link to another container (name:alias)
  704. --name="": Assign the specified name to the container. If no name is specific docker will generate a random name
  705. -P, --publish-all=false: Publish all exposed ports to the host interfaces
  706. The ``docker run`` command first ``creates`` a writeable container layer over
  707. the specified image, and then ``starts`` it using the specified command. That
  708. is, ``docker run`` is equivalent to the API ``/containers/create`` then
  709. ``/containers/(id)/start``.
  710. A stopped container can be restarted with all its previous changes intact using
  711. ``docker start``. See ``docker ps -a`` to view a list of all containers.
  712. The ``docker run`` command can be used in combination with ``docker commit`` to
  713. :ref:`change the command that a container runs <cli_commit_examples>`.
  714. See :ref:`port_redirection` for more detailed information about the ``--expose``,
  715. ``-p``, ``-P`` and ``--link`` parameters, and :ref:`working_with_links_names` for
  716. specific examples using ``--link``.
  717. Known Issues (run --volumes-from)
  718. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  719. * :issue:`2702`: "lxc-start: Permission denied - failed to mount"
  720. could indicate a permissions problem with AppArmor. Please see the
  721. issue for a workaround.
  722. Examples:
  723. ~~~~~~~~~
  724. .. code-block:: bash
  725. $ sudo docker run --cidfile /tmp/docker_test.cid ubuntu echo "test"
  726. This will create a container and print ``test`` to the console. The
  727. ``cidfile`` flag makes Docker attempt to create a new file and write the
  728. container ID to it. If the file exists already, Docker will return an
  729. error. Docker will close this file when ``docker run`` exits.
  730. .. code-block:: bash
  731. $ sudo docker run -t -i --rm ubuntu bash
  732. root@bc338942ef20:/# mount -t tmpfs none /mnt
  733. mount: permission denied
  734. This will *not* work, because by default, most potentially dangerous
  735. kernel capabilities are dropped; including ``cap_sys_admin`` (which is
  736. required to mount filesystems). However, the ``--privileged`` flag will
  737. allow it to run:
  738. .. code-block:: bash
  739. $ sudo docker run --privileged ubuntu bash
  740. root@50e3f57e16e6:/# mount -t tmpfs none /mnt
  741. root@50e3f57e16e6:/# df -h
  742. Filesystem Size Used Avail Use% Mounted on
  743. none 1.9G 0 1.9G 0% /mnt
  744. The ``--privileged`` flag gives *all* capabilities to the container,
  745. and it also lifts all the limitations enforced by the ``device``
  746. cgroup controller. In other words, the container can then do almost
  747. everything that the host can do. This flag exists to allow special
  748. use-cases, like running Docker within Docker.
  749. .. code-block:: bash
  750. $ sudo docker run -w /path/to/dir/ -i -t ubuntu pwd
  751. The ``-w`` lets the command being executed inside directory given,
  752. here ``/path/to/dir/``. If the path does not exists it is created inside the
  753. container.
  754. .. code-block:: bash
  755. $ sudo docker run -v `pwd`:`pwd` -w `pwd` -i -t ubuntu pwd
  756. The ``-v`` flag mounts the current working directory into the container.
  757. The ``-w`` lets the command being executed inside the current
  758. working directory, by changing into the directory to the value
  759. returned by ``pwd``. So this combination executes the command
  760. using the container, but inside the current working directory.
  761. .. code-block:: bash
  762. $ sudo docker run -v /doesnt/exist:/foo -w /foo -i -t ubuntu bash
  763. When the host directory of a bind-mounted volume doesn't exist, Docker
  764. will automatically create this directory on the host for you. In the
  765. example above, Docker will create the ``/doesnt/exist`` folder before
  766. starting your container.
  767. .. code-block:: bash
  768. $ sudo docker run -t -i -v /var/run/docker.sock:/var/run/docker.sock -v ./static-docker:/usr/bin/docker busybox sh
  769. By bind-mounting the docker unix socket and statically linked docker binary
  770. (such as that provided by https://get.docker.io), you give the container
  771. the full access to create and manipulate the host's docker daemon.
  772. .. code-block:: bash
  773. $ sudo docker run -p 127.0.0.1:80:8080 ubuntu bash
  774. This binds port ``8080`` of the container to port ``80`` on ``127.0.0.1`` of the
  775. host machine. :ref:`port_redirection` explains in detail how to manipulate ports
  776. in Docker.
  777. .. code-block:: bash
  778. $ sudo docker run --expose 80 ubuntu bash
  779. This exposes port ``80`` of the container for use within a link without
  780. publishing the port to the host system's interfaces. :ref:`port_redirection`
  781. explains in detail how to manipulate ports in Docker.
  782. .. code-block:: bash
  783. $ sudo docker run -e MYVAR1 --env MYVAR2=foo --env-file ./env.list ubuntu bash
  784. This sets environmental variables in the container. For illustration all three
  785. flags are shown here. Where ``-e``, ``--env`` take an environment variable and
  786. value, or if no "=" is provided, then that variable's current value is passed
  787. through (i.e. $MYVAR1 from the host is set to $MYVAR1 in the container). All
  788. three flags, ``-e``, ``--env`` and ``--env-file`` can be repeated.
  789. Regardless of the order of these three flags, the ``--env-file`` are processed
  790. first, and then ``-e``/``--env`` flags. This way, the ``-e`` or ``--env`` will
  791. override variables as needed.
  792. .. code-block:: bash
  793. $ cat ./env.list
  794. TEST_FOO=BAR
  795. $ sudo docker run --env TEST_FOO="This is a test" --env-file ./env.list busybox env | grep TEST_FOO
  796. TEST_FOO=This is a test
  797. The ``--env-file`` flag takes a filename as an argument and expects each line
  798. to be in the VAR=VAL format, mimicking the argument passed to ``--env``.
  799. Comment lines need only be prefixed with ``#``
  800. An example of a file passed with ``--env-file``
  801. .. code-block:: bash
  802. $ cat ./env.list
  803. TEST_FOO=BAR
  804. # this is a comment
  805. TEST_APP_DEST_HOST=10.10.0.127
  806. TEST_APP_DEST_PORT=8888
  807. # pass through this variable from the caller
  808. TEST_PASSTHROUGH
  809. $ sudo TEST_PASSTHROUGH=howdy docker run --env-file ./env.list busybox env
  810. HOME=/
  811. PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  812. HOSTNAME=5198e0745561
  813. TEST_FOO=BAR
  814. TEST_APP_DEST_HOST=10.10.0.127
  815. TEST_APP_DEST_PORT=8888
  816. TEST_PASSTHROUGH=howdy
  817. .. code-block:: bash
  818. $ sudo docker run --name console -t -i ubuntu bash
  819. This will create and run a new container with the container name
  820. being ``console``.
  821. .. code-block:: bash
  822. $ sudo docker run --link /redis:redis --name console ubuntu bash
  823. The ``--link`` flag will link the container named ``/redis`` into the
  824. newly created container with the alias ``redis``. The new container
  825. can access the network and environment of the redis container via
  826. environment variables. The ``--name`` flag will assign the name ``console``
  827. to the newly created container.
  828. .. code-block:: bash
  829. $ sudo docker run --volumes-from 777f7dc92da7,ba8c0c54f0f2:ro -i -t ubuntu pwd
  830. The ``--volumes-from`` flag mounts all the defined volumes from the
  831. referenced containers. Containers can be specified by a comma separated
  832. list or by repetitions of the ``--volumes-from`` argument. The container
  833. ID may be optionally suffixed with ``:ro`` or ``:rw`` to mount the volumes in
  834. read-only or read-write mode, respectively. By default, the volumes are mounted
  835. in the same mode (read write or read only) as the reference container.
  836. The ``-a`` flag tells ``docker run`` to bind to the container's stdin, stdout
  837. or stderr. This makes it possible to manipulate the output and input as needed.
  838. .. code-block:: bash
  839. $ sudo echo "test" | docker run -i -a stdin ubuntu cat -
  840. This pipes data into a container and prints the container's ID by attaching
  841. only to the container's stdin.
  842. .. code-block:: bash
  843. $ sudo docker run -a stderr ubuntu echo test
  844. This isn't going to print anything unless there's an error because we've only
  845. attached to the stderr of the container. The container's logs still store
  846. what's been written to stderr and stdout.
  847. .. code-block:: bash
  848. $ sudo cat somefile | docker run -i -a stdin mybuilder dobuild
  849. This is how piping a file into a container could be done for a build.
  850. The container's ID will be printed after the build is done and the build logs
  851. could be retrieved using ``docker logs``. This is useful if you need to pipe
  852. a file or something else into a container and retrieve the container's ID once
  853. the container has finished running.
  854. A complete example
  855. ..................
  856. .. code-block:: bash
  857. $ sudo docker run -d --name static static-web-files sh
  858. $ sudo docker run -d --expose=8098 --name riak riakserver
  859. $ sudo docker run -d -m 100m -e DEVELOPMENT=1 -e BRANCH=example-code -v $(pwd):/app/bin:ro --name app appserver
  860. $ sudo docker run -d -p 1443:443 --dns=dns.dev.org --dns-search=dev.org -v /var/log/httpd --volumes-from static --link riak --link app -h www.sven.dev.org --name web webserver
  861. $ sudo docker run -t -i --rm --volumes-from web -w /var/log/httpd busybox tail -f access.log
  862. This example shows 5 containers that might be set up to test a web application change:
  863. 1. Start a pre-prepared volume image ``static-web-files`` (in the background) that has CSS, image and static HTML in it, (with a ``VOLUME`` instruction in the ``Dockerfile`` to allow the web server to use those files);
  864. 2. Start a pre-prepared ``riakserver`` image, give the container name ``riak`` and expose port ``8098`` to any containers that link to it;
  865. 3. Start the ``appserver`` image, restricting its memory usage to 100MB, setting two environment variables ``DEVELOPMENT`` and ``BRANCH`` and bind-mounting the current directory (``$(pwd)``) in the container in read-only mode as ``/app/bin``;
  866. 4. Start the ``webserver``, mapping port ``443`` in the container to port ``1443`` on the Docker server, setting the DNS server to ``dns.dev.org`` and DNS search domain to ``dev.org``, creating a volume to put the log files into (so we can access it from another container), then importing the files from the volume exposed by the ``static`` container, and linking to all exposed ports from ``riak`` and ``app``. Lastly, we set the hostname to ``web.sven.dev.org`` so its consistent with the pre-generated SSL certificate;
  867. 5. Finally, we create a container that runs ``tail -f access.log`` using the logs volume from the ``web`` container, setting the workdir to ``/var/log/httpd``. The ``--rm`` option means that when the container exits, the container's layer is removed.
  868. .. _cli_save:
  869. ``save``
  870. ---------
  871. ::
  872. Usage: docker save IMAGE
  873. Save an image to a tar archive (streamed to stdout by default)
  874. -o, --output="": Write to an file, instead of STDOUT
  875. Produces a tarred repository to the standard output stream.
  876. Contains all parent layers, and all tags + versions, or specified repo:tag.
  877. It is used to create a backup that can then be used with ``docker load``
  878. .. code-block:: bash
  879. $ sudo docker save busybox > busybox.tar
  880. $ ls -sh b.tar
  881. 2.7M b.tar
  882. $ sudo docker save --output busybox.tar busybox
  883. $ ls -sh b.tar
  884. 2.7M b.tar
  885. $ sudo docker save -o fedora-all.tar fedora
  886. $ sudo docker save -o fedora-latest.tar fedora:latest
  887. .. _cli_search:
  888. ``search``
  889. ----------
  890. ::
  891. Usage: docker search TERM
  892. Search the docker index for images
  893. --no-trunc=false: Don't truncate output
  894. -s, --stars=0: Only displays with at least xxx stars
  895. -t, --trusted=false: Only show trusted builds
  896. See :ref:`searching_central_index` for more details on finding shared images
  897. from the commandline.
  898. .. _cli_start:
  899. ``start``
  900. ---------
  901. ::
  902. Usage: docker start [OPTIONS] CONTAINER
  903. Start a stopped container
  904. -a, --attach=false: Attach container᾿s stdout/stderr and forward all signals to the process
  905. -i, --interactive=false: Attach container᾿s stdin
  906. .. _cli_stop:
  907. ``stop``
  908. --------
  909. ::
  910. Usage: docker stop [OPTIONS] CONTAINER [CONTAINER...]
  911. Stop a running container (Send SIGTERM, and then SIGKILL after grace period)
  912. -t, --time=10: Number of seconds to wait for the container to stop before killing it.
  913. The main process inside the container will receive SIGTERM, and after a grace period, SIGKILL
  914. .. _cli_tag:
  915. ``tag``
  916. -------
  917. ::
  918. Usage: docker tag [OPTIONS] IMAGE [REGISTRYHOST/][USERNAME/]NAME[:TAG]
  919. Tag an image into a repository
  920. -f, --force=false: Force
  921. You can group your images together using names and
  922. tags, and then upload them to :ref:`working_with_the_repository`.
  923. .. _cli_top:
  924. ``top``
  925. -------
  926. ::
  927. Usage: docker top CONTAINER [ps OPTIONS]
  928. Lookup the running processes of a container
  929. .. _cli_version:
  930. ``version``
  931. -----------
  932. Show the version of the Docker client, daemon, and latest released version.
  933. .. _cli_wait:
  934. ``wait``
  935. --------
  936. ::
  937. Usage: docker wait [OPTIONS] NAME
  938. Block until a container stops, then print its exit code.