cli.rst 43 KB

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