github.com/sbward/docker@v1.4.2-0.20150114010528-c9dab702bed3/docs/sources/reference/commandline/cli.md (about) 1 page_title: Command Line Interface 2 page_description: Docker's CLI command description and usage 3 page_keywords: Docker, Docker documentation, CLI, command line 4 5 # Command Line 6 7 To list available commands, either run `docker` with no parameters 8 or execute `docker help`: 9 10 $ sudo docker 11 Usage: docker [OPTIONS] COMMAND [arg...] 12 -H, --host=[]: The socket(s) to bind to in daemon mode, specified using one or more tcp://host:port, unix:///path/to/socket, fd://* or fd://socketfd. 13 14 A self-sufficient runtime for Linux containers. 15 16 ... 17 18 ## Help 19 To list the help on any command just execute the command, followed by the `--help` option. 20 21 $ sudo docker run --help 22 23 Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...] 24 25 Run a command in a new container 26 27 -a, --attach=[] Attach to STDIN, STDOUT or STDERR. 28 -c, --cpu-shares=0 CPU shares (relative weight) 29 ... 30 31 ## Option types 32 33 Single character commandline options can be combined, so rather than 34 typing `docker run -t -i --name test busybox sh`, 35 you can write `docker run -ti --name test busybox sh`. 36 37 ### Boolean 38 39 Boolean options look like `-d=false`. The value you 40 see is the default value which gets set if you do **not** use the 41 boolean flag. If you do call `run -d`, that sets the 42 opposite boolean value, so in this case, `true`, and 43 so `docker run -d` **will** run in "detached" mode, 44 in the background. Other boolean options are similar – specifying them 45 will set the value to the opposite of the default value. 46 47 ### Multi 48 49 Options like `-a=[]` indicate they can be specified multiple times: 50 51 $ sudo docker run -a stdin -a stdout -a stderr -i -t ubuntu /bin/bash 52 53 Sometimes this can use a more complex value string, as for `-v`: 54 55 $ sudo docker run -v /host:/container example/mysql 56 57 ### Strings and Integers 58 59 Options like `--name=""` expect a string, and they 60 can only be specified once. Options like `-c=0` 61 expect an integer, and they can only be specified once. 62 63 ## daemon 64 65 Usage: docker [OPTIONS] COMMAND [arg...] 66 67 A self-sufficient runtime for linux containers. 68 69 Options: 70 --api-enable-cors=false Enable CORS headers in the remote API 71 -b, --bridge="" Attach containers to a pre-existing network bridge 72 use 'none' to disable container networking 73 --bip="" Use this CIDR notation address for the network bridge's IP, not compatible with -b 74 -D, --debug=false Enable debug mode 75 -d, --daemon=false Enable daemon mode 76 --dns=[] Force Docker to use specific DNS servers 77 --dns-search=[] Force Docker to use specific DNS search domains 78 -e, --exec-driver="native" Force the Docker runtime to use a specific exec driver 79 --fixed-cidr="" IPv4 subnet for fixed IPs (e.g.: 10.20.0.0/16) 80 this subnet must be nested in the bridge subnet (which is defined by -b or --bip) 81 --fixed-cidr-v6="" IPv6 subnet for global IPs (e.g.: 2a00:1450::/64) 82 -G, --group="docker" Group to assign the unix socket specified by -H when running in daemon mode 83 use '' (the empty string) to disable setting of a group 84 -g, --graph="/var/lib/docker" Path to use as the root of the Docker runtime 85 -H, --host=[] The socket(s) to bind to in daemon mode or connect to in client mode, specified using one or more tcp://host:port, unix:///path/to/socket, fd://* or fd://socketfd. 86 --icc=true Allow unrestricted inter-container and Docker daemon host communication 87 --insecure-registry=[] Enable insecure communication with specified registries (disables certificate verification for HTTPS and enables HTTP fallback) (e.g., localhost:5000 or 10.20.0.0/16) 88 --ip=0.0.0.0 Default IP address to use when binding container ports 89 --ip-forward=true Enable net.ipv4.ip_forward and IPv6 forwarding if --fixed-cidr-v6 is defined. IPv6 forwarding may interfere with your existing IPv6 configuration when using Router Advertisement. 90 --ip-masq=true Enable IP masquerading for bridge's IP range 91 --iptables=true Enable Docker's addition of iptables rules 92 --ipv6=false Enable Docker IPv6 support 93 -l, --log-level="info" Set the logging level 94 --label=[] Set key=value labels to the daemon (displayed in `docker info`) 95 --mtu=0 Set the containers network MTU 96 if no value is provided: default to the default route MTU or 1500 if no default route is available 97 -p, --pidfile="/var/run/docker.pid" Path to use for daemon PID file 98 --registry-mirror=[] Specify a preferred Docker registry mirror 99 -s, --storage-driver="" Force the Docker runtime to use a specific storage driver 100 --selinux-enabled=false Enable selinux support. SELinux does not presently support the BTRFS storage driver 101 --storage-opt=[] Set storage driver options 102 --tls=false Use TLS; implied by --tlsverify flag 103 --tlscacert="/home/sven/.docker/ca.pem" Trust only remotes providing a certificate signed by the CA given here 104 --tlscert="/home/sven/.docker/cert.pem" Path to TLS certificate file 105 --tlskey="/home/sven/.docker/key.pem" Path to TLS key file 106 --tlsverify=false Use TLS and verify the remote (daemon: verify client, client: verify daemon) 107 -v, --version=false Print version information and quit 108 109 Options with [] may be specified multiple times. 110 111 The Docker daemon is the persistent process that manages containers. 112 Docker uses the same binary for both the daemon and client. To run the 113 daemon you provide the `-d` flag. 114 115 116 To run the daemon with debug output, use `docker -d -D`. 117 118 ### Daemon socket option 119 120 The Docker daemon can listen for [Docker Remote API](/reference/api/docker_remote_api/) 121 requests via three different types of Socket: `unix`, `tcp`, and `fd`. 122 123 By default, a `unix` domain socket (or IPC socket) is created at `/var/run/docker.sock`, 124 requiring either `root` permission, or `docker` group membership. 125 126 If you need to access the Docker daemon remotely, you need to enable the `tcp` 127 Socket. Beware that the default setup provides un-encrypted and un-authenticated 128 direct access to the Docker daemon - and should be secured either using the 129 [built in HTTPS encrypted socket](/articles/https/), or by putting a secure web 130 proxy in front of it. You can listen on port `2375` on all network interfaces 131 with `-H tcp://0.0.0.0:2375`, or on a particular network interface using its IP 132 address: `-H tcp://192.168.59.103:2375`. It is conventional to use port `2375` 133 for un-encrypted, and port `2376` for encrypted communication with the daemon. 134 135 > **Note** If you're using an HTTPS encrypted socket, keep in mind that only TLS1.0 136 > and greater are supported. Protocols SSLv3 and under are not supported anymore 137 > for security reasons. 138 139 On Systemd based systems, you can communicate with the daemon via 140 [systemd socket activation](http://0pointer.de/blog/projects/socket-activation.html), use 141 `docker -d -H fd://`. Using `fd://` will work perfectly for most setups but 142 you can also specify individual sockets: `docker -d -H fd://3`. If the 143 specified socket activated files aren't found, then Docker will exit. You 144 can find examples of using Systemd socket activation with Docker and 145 Systemd in the [Docker source tree]( 146 https://github.com/docker/docker/tree/master/contrib/init/systemd/). 147 148 You can configure the Docker daemon to listen to multiple sockets at the same 149 time using multiple `-H` options: 150 151 # listen using the default unix socket, and on 2 specific IP addresses on this host. 152 docker -d -H unix:///var/run/docker.sock -H tcp://192.168.59.106 -H tcp://10.10.10.2 153 154 The Docker client will honor the `DOCKER_HOST` environment variable to set 155 the `-H` flag for the client. 156 157 $ sudo docker -H tcp://0.0.0.0:2375 ps 158 # or 159 $ export DOCKER_HOST="tcp://0.0.0.0:2375" 160 $ sudo docker ps 161 # both are equal 162 163 Setting the `DOCKER_TLS_VERIFY` environment variable to any value other than the empty 164 string is equivalent to setting the `--tlsverify` flag. The following are equivalent: 165 166 $ sudo docker --tlsverify ps 167 # or 168 $ export DOCKER_TLS_VERIFY=1 169 $ sudo docker ps 170 171 ### Daemon storage-driver option 172 173 The Docker daemon has support for several different image layer storage drivers: `aufs`, 174 `devicemapper`, `btrfs` and `overlay`. 175 176 The `aufs` driver is the oldest, but is based on a Linux kernel patch-set that 177 is unlikely to be merged into the main kernel. These are also known to cause some 178 serious kernel crashes. However, `aufs` is also the only storage driver that allows 179 containers to share executable and shared library memory, so is a useful choice 180 when running thousands of containers with the same program or libraries. 181 182 The `devicemapper` driver uses thin provisioning and Copy on Write (CoW) 183 snapshots. For each devicemapper graph location – typically 184 `/var/lib/docker/devicemapper` – a thin pool is created based on two block 185 devices, one for data and one for metadata. By default, these block devices 186 are created automatically by using loopback mounts of automatically created 187 sparse files. Refer to [Storage driver options](#storage-driver-options) below 188 for a way how to customize this setup. 189 [~jpetazzo/Resizing Docker containers with the Device Mapper plugin]( 190 http://jpetazzo.github.io/2014/01/29/docker-device-mapper-resize/) article 191 explains how to tune your existing setup without the use of options. 192 193 The `btrfs` driver is very fast for `docker build` - but like `devicemapper` does not 194 share executable memory between devices. Use `docker -d -s btrfs -g /mnt/btrfs_partition`. 195 196 The `overlay` is a very fast union filesystem. It is now merged in the main 197 Linux kernel as of [3.18.0](https://lkml.org/lkml/2014/10/26/137). 198 Call `docker -d -s overlay` to use it. 199 > **Note:** 200 > It is currently unsupported on `btrfs` or any Copy on Write filesystem 201 > and should only be used over `ext4` partitions. 202 203 #### Storage driver options 204 205 Particular storage-driver can be configured with options specified with 206 `--storage-opt` flags. The only driver accepting options is `devicemapper` as 207 of now. All its options are prefixed with `dm`. 208 209 Currently supported options are: 210 211 * `dm.basesize` 212 213 Specifies the size to use when creating the base device, which limits the 214 size of images and containers. The default value is 10G. Note, thin devices 215 are inherently "sparse", so a 10G device which is mostly empty doesn't use 216 10 GB of space on the pool. However, the filesystem will use more space for 217 the empty case the larger the device is. 218 219 **Warning**: This value affects the system-wide "base" empty filesystem 220 that may already be initialized and inherited by pulled images. Typically, 221 a change to this value will require additional steps to take effect: 222 223 $ sudo service docker stop 224 $ sudo rm -rf /var/lib/docker 225 $ sudo service docker start 226 227 Example use: 228 229 $ sudo docker -d --storage-opt dm.basesize=20G 230 231 * `dm.loopdatasize` 232 233 Specifies the size to use when creating the loopback file for the "data" 234 device which is used for the thin pool. The default size is 100G. Note that 235 the file is sparse, so it will not initially take up this much space. 236 237 Example use: 238 239 $ sudo docker -d --storage-opt dm.loopdatasize=200G 240 241 * `dm.loopmetadatasize` 242 243 Specifies the size to use when creating the loopback file for the 244 "metadata" device which is used for the thin pool. The default size is 2G. 245 Note that the file is sparse, so it will not initially take up this much 246 space. 247 248 Example use: 249 250 $ sudo docker -d --storage-opt dm.loopmetadatasize=4G 251 252 * `dm.fs` 253 254 Specifies the filesystem type to use for the base device. The supported 255 options are "ext4" and "xfs". The default is "ext4" 256 257 Example use: 258 259 $ sudo docker -d --storage-opt dm.fs=xfs 260 261 * `dm.mkfsarg` 262 263 Specifies extra mkfs arguments to be used when creating the base device. 264 265 Example use: 266 267 $ sudo docker -d --storage-opt "dm.mkfsarg=-O ^has_journal" 268 269 * `dm.mountopt` 270 271 Specifies extra mount options used when mounting the thin devices. 272 273 Example use: 274 275 $ sudo docker -d --storage-opt dm.mountopt=nodiscard 276 277 * `dm.datadev` 278 279 Specifies a custom blockdevice to use for data for the thin pool. 280 281 If using a block device for device mapper storage, ideally both datadev and 282 metadatadev should be specified to completely avoid using the loopback 283 device. 284 285 Example use: 286 287 $ sudo docker -d \ 288 --storage-opt dm.datadev=/dev/sdb1 \ 289 --storage-opt dm.metadatadev=/dev/sdc1 290 291 * `dm.metadatadev` 292 293 Specifies a custom blockdevice to use for metadata for the thin pool. 294 295 For best performance the metadata should be on a different spindle than the 296 data, or even better on an SSD. 297 298 If setting up a new metadata pool it is required to be valid. This can be 299 achieved by zeroing the first 4k to indicate empty metadata, like this: 300 301 $ dd if=/dev/zero of=$metadata_dev bs=4096 count=1 302 303 Example use: 304 305 $ sudo docker -d \ 306 --storage-opt dm.datadev=/dev/sdb1 \ 307 --storage-opt dm.metadatadev=/dev/sdc1 308 309 * `dm.blocksize` 310 311 Specifies a custom blocksize to use for the thin pool. The default 312 blocksize is 64K. 313 314 Example use: 315 316 $ sudo docker -d --storage-opt dm.blocksize=512K 317 318 * `dm.blkdiscard` 319 320 Enables or disables the use of blkdiscard when removing devicemapper 321 devices. This is enabled by default (only) if using loopback devices and is 322 required to res-parsify the loopback file on image/container removal. 323 324 Disabling this on loopback can lead to *much* faster container removal 325 times, but will make the space used in `/var/lib/docker` directory not be 326 returned to the system for other use when containers are removed. 327 328 Example use: 329 330 $ sudo docker -d --storage-opt dm.blkdiscard=false 331 332 ### Docker exec-driver option 333 334 The Docker daemon uses a specifically built `libcontainer` execution driver as its 335 interface to the Linux kernel `namespaces`, `cgroups`, and `SELinux`. 336 337 There is still legacy support for the original [LXC userspace tools]( 338 https://linuxcontainers.org/) via the `lxc` execution driver, however, this is 339 not where the primary development of new functionality is taking place. 340 Add `-e lxc` to the daemon flags to use the `lxc` execution driver. 341 342 343 ### Daemon DNS options 344 345 To set the DNS server for all Docker containers, use 346 `docker -d --dns 8.8.8.8`. 347 348 To set the DNS search domain for all Docker containers, use 349 `docker -d --dns-search example.com`. 350 351 ### Insecure registries 352 353 Docker considers a private registry either secure or insecure. 354 In the rest of this section, *registry* is used for *private registry*, and `myregistry:5000` 355 is a placeholder example for a private registry. 356 357 A secure registry uses TLS and a copy of its CA certificate is placed on the Docker host at 358 `/etc/docker/certs.d/myregistry:5000/ca.crt`. 359 An insecure registry is either not using TLS (i.e., listening on plain text HTTP), or is using 360 TLS with a CA certificate not known by the Docker daemon. The latter can happen when the 361 certificate was not found under `/etc/docker/certs.d/myregistry:5000/`, or if the certificate 362 verification failed (i.e., wrong CA). 363 364 By default, Docker assumes all, but local (see local registries below), registries are secure. 365 Communicating with an insecure registry is not possible if Docker assumes that registry is secure. 366 In order to communicate with an insecure registry, the Docker daemon requires `--insecure-registry` 367 in one of the following two forms: 368 369 * `--insecure-registry myregistry:5000` tells the Docker daemon that myregistry:5000 should be considered insecure. 370 * `--insecure-registry 10.1.0.0/16` tells the Docker daemon that all registries whose domain resolve to an IP address is part 371 of the subnet described by the CIDR syntax, should be considered insecure. 372 373 The flag can be used multiple times to allow multiple registries to be marked as insecure. 374 375 If an insecure registry is not marked as insecure, `docker pull`, `docker push`, and `docker search` 376 will result in an error message prompting the user to either secure or pass the `--insecure-registry` 377 flag to the Docker daemon as described above. 378 379 Local registries, whose IP address falls in the 127.0.0.0/8 range, are automatically marked as insecure 380 as of Docker 1.3.2. It is not recommended to rely on this, as it may change in the future. 381 382 ### Running a Docker daemon behind a HTTPS_PROXY 383 384 When running inside a LAN that uses a `HTTPS` proxy, the Docker Hub certificates 385 will be replaced by the proxy's certificates. These certificates need to be added 386 to your Docker host's configuration: 387 388 1. Install the `ca-certificates` package for your distribution 389 2. Ask your network admin for the proxy's CA certificate and append them to 390 `/etc/pki/tls/certs/ca-bundle.crt` 391 3. Then start your Docker daemon with `HTTPS_PROXY=http://username:password@proxy:port/ docker -d`. 392 The `username:` and `password@` are optional - and are only needed if your proxy 393 is set up to require authentication. 394 395 This will only add the proxy and authentication to the Docker daemon's requests - 396 your `docker build`s and running containers will need extra configuration to use 397 the proxy 398 399 ### Miscellaneous options 400 401 IP masquerading uses address translation to allow containers without a public IP to talk 402 to other machines on the Internet. This may interfere with some network topologies and 403 can be disabled with --ip-masq=false. 404 405 Docker supports softlinks for the Docker data directory 406 (`/var/lib/docker`) and for `/var/lib/docker/tmp`. The `DOCKER_TMPDIR` and the data directory can be set like this: 407 408 DOCKER_TMPDIR=/mnt/disk2/tmp /usr/local/bin/docker -d -D -g /var/lib/docker -H unix:// > /var/lib/boot2docker/docker.log 2>&1 409 # or 410 export DOCKER_TMPDIR=/mnt/disk2/tmp 411 /usr/local/bin/docker -d -D -g /var/lib/docker -H unix:// > /var/lib/boot2docker/docker.log 2>&1 412 413 414 ## attach 415 416 Usage: docker attach [OPTIONS] CONTAINER 417 418 Attach to a running container 419 420 --no-stdin=false Do not attach STDIN 421 --sig-proxy=true Proxy all received signals to the process (non-TTY mode only). SIGCHLD, SIGKILL, and SIGSTOP are not proxied. 422 423 The `attach` command lets you view or interact with any running container's 424 primary process (`pid 1`). 425 426 You can attach to the same contained process multiple times simultaneously, screen 427 sharing style, or quickly view the progress of your daemonized process. 428 429 > **Note:** This command is not for running a new process in a container. 430 > See: [`docker exec`](#exec). 431 432 You can detach from the container again (and leave it running) with 433 `CTRL-p CTRL-q` (for a quiet exit), or `CTRL-c` which will send a 434 SIGKILL to the container, or `CTRL-\` to get a stacktrace of the 435 Docker client when it quits. When you detach from the container's 436 process the exit code will be returned to the client. 437 438 To stop a container, use `docker stop`. 439 440 To kill the container, use `docker kill`. 441 442 #### Examples 443 444 $ ID=$(sudo docker run -d ubuntu /usr/bin/top -b) 445 $ sudo docker attach $ID 446 top - 02:05:52 up 3:05, 0 users, load average: 0.01, 0.02, 0.05 447 Tasks: 1 total, 1 running, 0 sleeping, 0 stopped, 0 zombie 448 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 449 Mem: 373572k total, 355560k used, 18012k free, 27872k buffers 450 Swap: 786428k total, 0k used, 786428k free, 221740k cached 451 452 PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 453 1 root 20 0 17200 1116 912 R 0 0.3 0:00.03 top 454 455 top - 02:05:55 up 3:05, 0 users, load average: 0.01, 0.02, 0.05 456 Tasks: 1 total, 1 running, 0 sleeping, 0 stopped, 0 zombie 457 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 458 Mem: 373572k total, 355244k used, 18328k free, 27872k buffers 459 Swap: 786428k total, 0k used, 786428k free, 221776k cached 460 461 PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 462 1 root 20 0 17208 1144 932 R 0 0.3 0:00.03 top 463 464 465 top - 02:05:58 up 3:06, 0 users, load average: 0.01, 0.02, 0.05 466 Tasks: 1 total, 1 running, 0 sleeping, 0 stopped, 0 zombie 467 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 468 Mem: 373572k total, 355780k used, 17792k free, 27880k buffers 469 Swap: 786428k total, 0k used, 786428k free, 221776k cached 470 471 PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 472 1 root 20 0 17208 1144 932 R 0 0.3 0:00.03 top 473 ^C$ 474 $ sudo docker stop $ID 475 476 ## build 477 478 Usage: docker build [OPTIONS] PATH | URL | - 479 480 Build a new image from the source code at PATH 481 482 -f, --file="" Location of the Dockerfile to use. Default is 'Dockerfile' at the root of the build context 483 --force-rm=false Always remove intermediate containers, even after unsuccessful builds 484 --no-cache=false Do not use cache when building the image 485 -q, --quiet=false Suppress the verbose output generated by the containers 486 --rm=true Remove intermediate containers after a successful build 487 -t, --tag="" Repository name (and optionally a tag) to be applied to the resulting image in case of success 488 489 Use this command to build Docker images from a Dockerfile and a 490 "context". 491 492 The files at `PATH` or `URL` are called the "context" of the build. The 493 build process may refer to any of the files in the context, for example 494 when using an [*ADD*](/reference/builder/#add) instruction. 495 When a single Dockerfile is given as `URL` or is piped through `STDIN` 496 (`docker build - < Dockerfile`), then no context is set. 497 498 When a Git repository is set as `URL`, then the repository is used as 499 the context. The Git repository is cloned with its submodules 500 (`git clone -recursive`). A fresh `git clone` occurs in a temporary directory 501 on your local host, and then this is sent to the Docker daemon as the 502 context. This way, your local user credentials and VPN's etc can be 503 used to access private repositories. 504 505 If a file named `.dockerignore` exists in the root of `PATH` then it 506 is interpreted as a newline-separated list of exclusion patterns. 507 Exclusion patterns match files or directories relative to `PATH` that 508 will be excluded from the context. Globbing is done using Go's 509 [filepath.Match](http://golang.org/pkg/path/filepath#Match) rules. 510 511 Please note that `.dockerignore` files in other subdirectories are 512 considered as normal files. Filepaths in .dockerignore are absolute with 513 the current directory as the root. Wildcards are allowed but the search 514 is not recursive. 515 516 #### Example .dockerignore file 517 */temp* 518 */*/temp* 519 temp? 520 521 The first line above `*/temp*`, would ignore all files with names starting with 522 `temp` from any subdirectory below the root directory. For example, a file named 523 `/somedir/temporary.txt` would be ignored. The second line `*/*/temp*`, will 524 ignore files starting with name `temp` from any subdirectory that is two levels 525 below the root directory. For example, the file `/somedir/subdir/temporary.txt` 526 would get ignored in this case. The last line in the above example `temp?` 527 will ignore the files that match the pattern from the root directory. 528 For example, the files `tempa`, `tempb` are ignored from the root directory. 529 Currently there is no support for regular expressions. Formats 530 like `[^temp*]` are ignored. 531 532 By default the `docker build` command will look for a `Dockerfile` at the 533 root of the build context. The `-f`, `--file`, option lets you specify 534 the path to an alternative file to use instead. This is useful 535 in cases where the same set of files are used for multiple builds. The path 536 must be to a file within the build context. If a relative path is specified 537 then it must to be relative to the current directory. 538 539 540 See also: 541 542 [*Dockerfile Reference*](/reference/builder). 543 544 #### Examples 545 546 $ sudo docker build . 547 Uploading context 10240 bytes 548 Step 1 : FROM busybox 549 Pulling repository busybox 550 ---> e9aa60c60128MB/2.284 MB (100%) endpoint: https://cdn-registry-1.docker.io/v1/ 551 Step 2 : RUN ls -lh / 552 ---> Running in 9c9e81692ae9 553 total 24 554 drwxr-xr-x 2 root root 4.0K Mar 12 2013 bin 555 drwxr-xr-x 5 root root 4.0K Oct 19 00:19 dev 556 drwxr-xr-x 2 root root 4.0K Oct 19 00:19 etc 557 drwxr-xr-x 2 root root 4.0K Nov 15 23:34 lib 558 lrwxrwxrwx 1 root root 3 Mar 12 2013 lib64 -> lib 559 dr-xr-xr-x 116 root root 0 Nov 15 23:34 proc 560 lrwxrwxrwx 1 root root 3 Mar 12 2013 sbin -> bin 561 dr-xr-xr-x 13 root root 0 Nov 15 23:34 sys 562 drwxr-xr-x 2 root root 4.0K Mar 12 2013 tmp 563 drwxr-xr-x 2 root root 4.0K Nov 15 23:34 usr 564 ---> b35f4035db3f 565 Step 3 : CMD echo Hello world 566 ---> Running in 02071fceb21b 567 ---> f52f38b7823e 568 Successfully built f52f38b7823e 569 Removing intermediate container 9c9e81692ae9 570 Removing intermediate container 02071fceb21b 571 572 This example specifies that the `PATH` is 573 `.`, and so all the files in the local directory get 574 `tar`d and sent to the Docker daemon. The `PATH` 575 specifies where to find the files for the "context" of the build on the 576 Docker daemon. Remember that the daemon could be running on a remote 577 machine and that no parsing of the Dockerfile 578 happens at the client side (where you're running 579 `docker build`). That means that *all* the files at 580 `PATH` get sent, not just the ones listed to 581 [*ADD*](/reference/builder/#add) in the Dockerfile. 582 583 The transfer of context from the local machine to the Docker daemon is 584 what the `docker` client means when you see the 585 "Sending build context" message. 586 587 If you wish to keep the intermediate containers after the build is 588 complete, you must use `--rm=false`. This does not 589 affect the build cache. 590 591 $ sudo docker build . 592 Uploading context 18.829 MB 593 Uploading context 594 Step 0 : FROM busybox 595 ---> 769b9341d937 596 Step 1 : CMD echo Hello world 597 ---> Using cache 598 ---> 99cc1ad10469 599 Successfully built 99cc1ad10469 600 $ echo ".git" > .dockerignore 601 $ sudo docker build . 602 Uploading context 6.76 MB 603 Uploading context 604 Step 0 : FROM busybox 605 ---> 769b9341d937 606 Step 1 : CMD echo Hello world 607 ---> Using cache 608 ---> 99cc1ad10469 609 Successfully built 99cc1ad10469 610 611 This example shows the use of the `.dockerignore` file to exclude the `.git` 612 directory from the context. Its effect can be seen in the changed size of the 613 uploaded context. 614 615 $ sudo docker build -t vieux/apache:2.0 . 616 617 This will build like the previous example, but it will then tag the 618 resulting image. The repository name will be `vieux/apache` 619 and the tag will be `2.0` 620 621 $ sudo docker build - < Dockerfile 622 623 This will read a Dockerfile from `STDIN` without context. Due to the 624 lack of a context, no contents of any local directory will be sent to 625 the Docker daemon. Since there is no context, a Dockerfile `ADD` only 626 works if it refers to a remote URL. 627 628 $ sudo docker build - < context.tar.gz 629 630 This will build an image for a compressed context read from `STDIN`. 631 Supported formats are: bzip2, gzip and xz. 632 633 $ sudo docker build github.com/creack/docker-firefox 634 635 This will clone the GitHub repository and use the cloned repository as 636 context. The Dockerfile at the root of the 637 repository is used as Dockerfile. Note that you 638 can specify an arbitrary Git repository by using the `git://` or `git@` 639 schema. 640 641 $ sudo docker build -f Dockerfile.debug . 642 643 This will use a file called `Dockerfile.debug` for the build 644 instructions instead of `Dockerfile`. 645 646 $ sudo docker build -f dockerfiles/Dockerfile.debug -t myapp_debug . 647 $ sudo docker build -f dockerfiles/Dockerfile.prod -t myapp_prod . 648 649 The above commands will build the current build context (as specified by 650 the `.`) twice, once using a debug version of a `Dockerfile` and once using 651 a production version. 652 653 $ cd /home/me/myapp/some/dir/really/deep 654 $ sudo docker build -f /home/me/myapp/dockerfiles/debug /home/me/myapp 655 $ sudo docker build -f ../../../../dockerfiles/debug /home/me/myapp 656 657 These two `docker build` commands do the exact same thing. They both 658 use the contents of the `debug` file instead of looking for a `Dockerfile` 659 and will use `/home/me/myapp` as the root of the build context. Note that 660 `debug` is in the directory structure of the build context, regardless of how 661 you refer to it on the command line. 662 663 > **Note:** `docker build` will return a `no such file or directory` error 664 > if the file or directory does not exist in the uploaded context. This may 665 > happen if there is no context, or if you specify a file that is elsewhere 666 > on the Host system. The context is limited to the current directory (and its 667 > children) for security reasons, and to ensure repeatable builds on remote 668 > Docker hosts. This is also the reason why `ADD ../file` will not work. 669 670 ## commit 671 672 Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]] 673 674 Create a new image from a container's changes 675 676 -a, --author="" Author (e.g., "John Hannibal Smith <hannibal@a-team.com>") 677 -m, --message="" Commit message 678 -p, --pause=true Pause container during commit 679 680 It can be useful to commit a container's file changes or settings into a 681 new image. This allows you debug a container by running an interactive 682 shell, or to export a working dataset to another server. Generally, it 683 is better to use Dockerfiles to manage your images in a documented and 684 maintainable way. 685 686 By default, the container being committed and its processes will be paused 687 while the image is committed. This reduces the likelihood of 688 encountering data corruption during the process of creating the commit. 689 If this behavior is undesired, set the 'p' option to false. 690 691 #### Commit an existing container 692 693 $ sudo docker ps 694 ID IMAGE COMMAND CREATED STATUS PORTS 695 c3f279d17e0a ubuntu:12.04 /bin/bash 7 days ago Up 25 hours 696 197387f1b436 ubuntu:12.04 /bin/bash 7 days ago Up 25 hours 697 $ sudo docker commit c3f279d17e0a SvenDowideit/testimage:version3 698 f5283438590d 699 $ sudo docker images | head 700 REPOSITORY TAG ID CREATED VIRTUAL SIZE 701 SvenDowideit/testimage version3 f5283438590d 16 seconds ago 335.7 MB 702 703 ## cp 704 705 Copy files/folders from a container's filesystem to the host 706 path. Paths are relative to the root of the filesystem. 707 708 Usage: docker cp CONTAINER:PATH HOSTPATH 709 710 Copy files/folders from the PATH to the HOSTPATH 711 712 ## create 713 714 Creates a new container. 715 716 Usage: docker create [OPTIONS] IMAGE [COMMAND] [ARG...] 717 718 Create a new container 719 720 -a, --attach=[] Attach to STDIN, STDOUT or STDERR. 721 --add-host=[] Add a custom host-to-IP mapping (host:ip) 722 -c, --cpu-shares=0 CPU shares (relative weight) 723 --cap-add=[] Add Linux capabilities 724 --cap-drop=[] Drop Linux capabilities 725 --cidfile="" Write the container ID to the file 726 --cpuset="" CPUs in which to allow execution (0-3, 0,1) 727 --device=[] Add a host device to the container (e.g. --device=/dev/sdc:/dev/xvdc:rwm) 728 --dns=[] Set custom DNS servers 729 --dns-search=[] Set custom DNS search domains (Use --dns-search=. if you don't wish to set the search domain) 730 -e, --env=[] Set environment variables 731 --entrypoint="" Overwrite the default ENTRYPOINT of the image 732 --env-file=[] Read in a line delimited file of environment variables 733 --expose=[] Expose a port or a range of ports (e.g. --expose=3300-3310) from the container without publishing it to your host 734 -h, --hostname="" Container host name 735 -i, --interactive=false Keep STDIN open even if not attached 736 --ipc="" Default is to create a private IPC namespace (POSIX SysV IPC) for the container 737 'container:<name|id>': reuses another container shared memory, semaphores and message queues 738 'host': use the host shared memory,semaphores and message queues inside the container. Note: the host mode gives the container full access to local shared memory and is therefore considered insecure. 739 --link=[] Add link to another container in the form of name:alias 740 --lxc-conf=[] (lxc exec-driver only) Add custom lxc options --lxc-conf="lxc.cgroup.cpuset.cpus = 0,1" 741 -m, --memory="" Memory limit (format: <number><optional unit>, where unit = b, k, m or g) 742 --mac-address="" Container MAC address (e.g. 92:d0:c6:0a:29:33) 743 --name="" Assign a name to the container 744 --net="bridge" Set the Network mode for the container 745 'bridge': creates a new network stack for the container on the docker bridge 746 'none': no networking for this container 747 'container:<name|id>': reuses another container network stack 748 'host': use the host network stack inside the container. Note: the host mode gives the container full access to local system services such as D-bus and is therefore considered insecure. 749 -P, --publish-all=false Publish all exposed ports to random ports on the host interfaces 750 -p, --publish=[] Publish a container's port, or a range of ports (e.g., `-p 3300-3310`), to the host 751 format: ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort | containerPort 752 Both hostPort and containerPort can be specified as a range of ports. 753 When specifying ranges for both, the number of container ports in the range must match the number of host ports in the range. (e.g., `-p 1234-1236:1234-1236/tcp`) 754 (use 'docker port' to see the actual mapping) 755 --privileged=false Give extended privileges to this container 756 --restart="" Restart policy to apply when a container exits (no, on-failure[:max-retry], always) 757 --security-opt=[] Security Options 758 -t, --tty=false Allocate a pseudo-TTY 759 -u, --user="" Username or UID 760 -v, --volume=[] Bind mount a volume (e.g., from the host: -v /host:/container, from Docker: -v /container) 761 --volumes-from=[] Mount volumes from the specified container(s) 762 -w, --workdir="" Working directory inside the container 763 764 The `docker create` command creates a writeable container layer over 765 the specified image and prepares it for running the specified command. 766 The container ID is then printed to `STDOUT`. 767 This is similar to `docker run -d` except the container is never started. 768 You can then use the `docker start <container_id>` command to start the 769 container at any point. 770 771 This is useful when you want to set up a container configuration ahead 772 of time so that it is ready to start when you need it. 773 774 Note that volumes set by `create` may be over-ridden by options set with 775 `start`. 776 777 Please see the [run command](#run) section for more details. 778 779 #### Examples 780 781 $ sudo docker create -t -i fedora bash 782 6d8af538ec541dd581ebc2a24153a28329acb5268abe5ef868c1f1a261221752 783 $ sudo docker start -a -i 6d8af538ec5 784 bash-4.2# 785 786 As of v1.4.0 container volumes are initialized during the `docker create` 787 phase (i.e., `docker run` too). For example, this allows you to `create` the 788 `data` volume container, and then use it from another container: 789 790 $ docker create -v /data --name data ubuntu 791 240633dfbb98128fa77473d3d9018f6123b99c454b3251427ae190a7d951ad57 792 $ docker run --rm --volumes-from data ubuntu ls -la /data 793 total 8 794 drwxr-xr-x 2 root root 4096 Dec 5 04:10 . 795 drwxr-xr-x 48 root root 4096 Dec 5 04:11 .. 796 797 Similarly, `create` a host directory bind mounted volume container, which 798 can then be used from the subsequent container: 799 800 $ docker create -v /home/docker:/docker --name docker ubuntu 801 9aa88c08f319cd1e4515c3c46b0de7cc9aa75e878357b1e96f91e2c773029f03 802 $ docker run --rm --volumes-from docker ubuntu ls -la /docker 803 total 20 804 drwxr-sr-x 5 1000 staff 180 Dec 5 04:00 . 805 drwxr-xr-x 48 root root 4096 Dec 5 04:13 .. 806 -rw-rw-r-- 1 1000 staff 3833 Dec 5 04:01 .ash_history 807 -rw-r--r-- 1 1000 staff 446 Nov 28 11:51 .ashrc 808 -rw-r--r-- 1 1000 staff 25 Dec 5 04:00 .gitconfig 809 drwxr-sr-x 3 1000 staff 60 Dec 1 03:28 .local 810 -rw-r--r-- 1 1000 staff 920 Nov 28 11:51 .profile 811 drwx--S--- 2 1000 staff 460 Dec 5 00:51 .ssh 812 drwxr-xr-x 32 1000 staff 1140 Dec 5 04:01 docker 813 814 815 ## diff 816 817 List the changed files and directories in a container᾿s filesystem 818 819 Usage: docker diff CONTAINER 820 821 Inspect changes on a container's filesystem 822 823 There are 3 events that are listed in the `diff`: 824 825 1. `A` - Add 826 2. `D` - Delete 827 3. `C` - Change 828 829 For example: 830 831 $ sudo docker diff 7bb0e258aefe 832 833 C /dev 834 A /dev/kmsg 835 C /etc 836 A /etc/mtab 837 A /go 838 A /go/src 839 A /go/src/github.com 840 A /go/src/github.com/docker 841 A /go/src/github.com/docker/docker 842 A /go/src/github.com/docker/docker/.git 843 .... 844 845 ## events 846 847 Usage: docker events [OPTIONS] 848 849 Get real time events from the server 850 851 --since="" Show all events created since timestamp 852 --until="" Stream events until this timestamp 853 854 Docker containers will report the following events: 855 856 create, destroy, die, export, kill, oom, pause, restart, start, stop, unpause 857 858 and Docker images will report: 859 860 untag, delete 861 862 #### Filtering 863 864 The filtering flag (`-f` or `--filter`) format is of "key=value". If you would like to use 865 multiple filters, pass multiple flags (e.g., `--filter "foo=bar" --filter "bif=baz"`) 866 867 Using the same filter multiple times will be handled as a *OR*; for example 868 `--filter container=588a23dac085 --filter container=a8f7720b8c22` will display events for 869 container 588a23dac085 *OR* container a8f7720b8c22 870 871 Using multiple filters will be handled as a *AND*; for example 872 `--filter container=588a23dac085 --filter event=start` will display events for container 873 container 588a23dac085 *AND* the event type is *start* 874 875 Current filters: 876 * event 877 * image 878 * container 879 880 #### Examples 881 882 You'll need two shells for this example. 883 884 **Shell 1: Listening for events:** 885 886 $ sudo docker events 887 888 **Shell 2: Start and Stop containers:** 889 890 $ sudo docker start 4386fb97867d 891 $ sudo docker stop 4386fb97867d 892 $ sudo docker stop 7805c1d35632 893 894 **Shell 1: (Again .. now showing events):** 895 896 2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) start 897 2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) die 898 2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) stop 899 2014-05-10T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) die 900 2014-05-10T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) stop 901 902 **Show events in the past from a specified time:** 903 904 $ sudo docker events --since 1378216169 905 2014-03-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) die 906 2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) stop 907 2014-05-10T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) die 908 2014-03-10T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) stop 909 910 $ sudo docker events --since '2013-09-03' 911 2014-09-03T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) start 912 2014-09-03T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) die 913 2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) stop 914 2014-05-10T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) die 915 2014-09-03T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) stop 916 917 $ sudo docker events --since '2013-09-03 15:49:29 +0200 CEST' 918 2014-09-03T15:49:29.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) die 919 2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) stop 920 2014-05-10T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) die 921 2014-09-03T15:49:29.999999999Z07:00 7805c1d35632: (from redis:2.8) stop 922 923 **Filter events:** 924 925 $ sudo docker events --filter 'event=stop' 926 2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) stop 927 2014-09-03T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) stop 928 929 $ sudo docker events --filter 'image=ubuntu-1:14.04' 930 2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) start 931 2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) die 932 2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) stop 933 934 $ sudo docker events --filter 'container=7805c1d35632' 935 2014-05-10T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) die 936 2014-09-03T15:49:29.999999999Z07:00 7805c1d35632: (from redis:2.8) stop 937 938 $ sudo docker events --filter 'container=7805c1d35632' --filter 'container=4386fb97867d' 939 2014-09-03T15:49:29.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) die 940 2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) stop 941 2014-05-10T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) die 942 2014-09-03T15:49:29.999999999Z07:00 7805c1d35632: (from redis:2.8) stop 943 944 $ sudo docker events --filter 'container=7805c1d35632' --filter 'event=stop' 945 2014-09-03T15:49:29.999999999Z07:00 7805c1d35632: (from redis:2.8) stop 946 947 ## exec 948 949 Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...] 950 951 Run a command in a running container 952 953 -d, --detach=false Detached mode: run command in the background 954 -i, --interactive=false Keep STDIN open even if not attached 955 -t, --tty=false Allocate a pseudo-TTY 956 957 The `docker exec` command runs a new command in a running container. 958 959 The command started using `docker exec` will only run while the container's primary 960 process (`PID 1`) is running, and will not be restarted if the container is restarted. 961 962 If the container is paused, then the `docker exec` command will fail with an error: 963 964 $ docker pause test 965 test 966 $ docker ps 967 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 968 1ae3b36715d2 ubuntu:latest "bash" 17 seconds ago Up 16 seconds (Paused) test 969 $ docker exec test ls 970 FATA[0000] Error response from daemon: Container test is paused, unpause the container before exec 971 $ echo $? 972 1 973 974 #### Examples 975 976 $ sudo docker run --name ubuntu_bash --rm -i -t ubuntu bash 977 978 This will create a container named `ubuntu_bash` and start a Bash session. 979 980 $ sudo docker exec -d ubuntu_bash touch /tmp/execWorks 981 982 This will create a new file `/tmp/execWorks` inside the running container 983 `ubuntu_bash`, in the background. 984 985 $ sudo docker exec -it ubuntu_bash bash 986 987 This will create a new Bash session in the container `ubuntu_bash`. 988 989 ## export 990 991 Usage: docker export CONTAINER 992 993 Export the contents of a filesystem as a tar archive to STDOUT 994 995 For example: 996 997 $ sudo docker export red_panda > latest.tar 998 999 ## history 1000 1001 Usage: docker history [OPTIONS] IMAGE 1002 1003 Show the history of an image 1004 1005 --no-trunc=false Don't truncate output 1006 -q, --quiet=false Only show numeric IDs 1007 1008 To see how the `docker:latest` image was built: 1009 1010 $ sudo docker history docker 1011 IMAGE CREATED CREATED BY SIZE 1012 3e23a5875458790b7a806f95f7ec0d0b2a5c1659bfc899c89f939f6d5b8f7094 8 days ago /bin/sh -c #(nop) ENV LC_ALL=C.UTF-8 0 B 1013 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 1014 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 1015 4b137612be55ca69776c7f30c2d2dd0aa2e7d72059820abf3e25b629f887a084 6 weeks ago /bin/sh -c #(nop) ADD jessie.tar.xz in / 121 MB 1016 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 1017 511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158 9 months ago 0 B 1018 1019 ## images 1020 1021 Usage: docker images [OPTIONS] [REPOSITORY] 1022 1023 List images 1024 1025 -a, --all=false Show all images (by default filter out the intermediate image layers) 1026 -f, --filter=[] Provide filter values (i.e. 'dangling=true') 1027 --no-trunc=false Don't truncate output 1028 -q, --quiet=false Only show numeric IDs 1029 1030 The default `docker images` will show all top level 1031 images, their repository and tags, and their virtual size. 1032 1033 Docker images have intermediate layers that increase reusability, 1034 decrease disk usage, and speed up `docker build` by 1035 allowing each step to be cached. These intermediate layers are not shown 1036 by default. 1037 1038 The `VIRTUAL SIZE` is the cumulative space taken up by the image and all 1039 its parent images. This is also the disk space used by the contents of the 1040 Tar file created when you `docker save` an image. 1041 1042 An image will be listed more than once if it has multiple repository names 1043 or tags. This single image (identifiable by its matching `IMAGE ID`) 1044 uses up the `VIRTUAL SIZE` listed only once. 1045 1046 #### Listing the most recently created images 1047 1048 $ sudo docker images | head 1049 REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE 1050 <none> <none> 77af4d6b9913 19 hours ago 1.089 GB 1051 committ latest b6fa739cedf5 19 hours ago 1.089 GB 1052 <none> <none> 78a85c484f71 19 hours ago 1.089 GB 1053 docker latest 30557a29d5ab 20 hours ago 1.089 GB 1054 <none> <none> 5ed6274db6ce 24 hours ago 1.089 GB 1055 postgres 9 746b819f315e 4 days ago 213.4 MB 1056 postgres 9.3 746b819f315e 4 days ago 213.4 MB 1057 postgres 9.3.5 746b819f315e 4 days ago 213.4 MB 1058 postgres latest 746b819f315e 4 days ago 213.4 MB 1059 1060 1061 #### Listing the full length image IDs 1062 1063 $ sudo docker images --no-trunc | head 1064 REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE 1065 <none> <none> 77af4d6b9913e693e8d0b4b294fa62ade6054e6b2f1ffb617ac955dd63fb0182 19 hours ago 1.089 GB 1066 committest latest b6fa739cedf5ea12a620a439402b6004d057da800f91c7524b5086a5e4749c9f 19 hours ago 1.089 GB 1067 <none> <none> 78a85c484f71509adeaace20e72e941f6bdd2b25b4c75da8693efd9f61a37921 19 hours ago 1.089 GB 1068 docker latest 30557a29d5abc51e5f1d5b472e79b7e296f595abcf19fe6b9199dbbc809c6ff4 20 hours ago 1.089 GB 1069 <none> <none> 0124422dd9f9cf7ef15c0617cda3931ee68346455441d66ab8bdc5b05e9fdce5 20 hours ago 1.089 GB 1070 <none> <none> 18ad6fad340262ac2a636efd98a6d1f0ea775ae3d45240d3418466495a19a81b 22 hours ago 1.082 GB 1071 <none> <none> f9f1e26352f0a3ba6a0ff68167559f64f3e21ff7ada60366e2d44a04befd1d3a 23 hours ago 1.089 GB 1072 tryout latest 2629d1fa0b81b222fca63371ca16cbf6a0772d07759ff80e8d1369b926940074 23 hours ago 131.5 MB 1073 <none> <none> 5ed6274db6ceb2397844896966ea239290555e74ef307030ebb01ff91b1914df 24 hours ago 1.089 GB 1074 1075 #### Filtering 1076 1077 The filtering flag (`-f` or `--filter`) format is of "key=value". If there is more 1078 than one filter, then pass multiple flags (e.g., `--filter "foo=bar" --filter "bif=baz"`) 1079 1080 Current filters: 1081 * dangling (boolean - true or false) 1082 1083 ##### Untagged images 1084 1085 $ sudo docker images --filter "dangling=true" 1086 1087 REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE 1088 <none> <none> 8abc22fbb042 4 weeks ago 0 B 1089 <none> <none> 48e5f45168b9 4 weeks ago 2.489 MB 1090 <none> <none> bf747efa0e2f 4 weeks ago 0 B 1091 <none> <none> 980fe10e5736 12 weeks ago 101.4 MB 1092 <none> <none> dea752e4e117 12 weeks ago 101.4 MB 1093 <none> <none> 511136ea3c5a 8 months ago 0 B 1094 1095 This will display untagged images, that are the leaves of the images tree (not 1096 intermediary layers). These images occur when a new build of an image takes the 1097 `repo:tag` away from the image ID, leaving it untagged. A warning will be issued 1098 if trying to remove an image when a container is presently using it. 1099 By having this flag it allows for batch cleanup. 1100 1101 Ready for use by `docker rmi ...`, like: 1102 1103 $ sudo docker rmi $(sudo docker images -f "dangling=true" -q) 1104 1105 8abc22fbb042 1106 48e5f45168b9 1107 bf747efa0e2f 1108 980fe10e5736 1109 dea752e4e117 1110 511136ea3c5a 1111 1112 NOTE: Docker will warn you if any containers exist that are using these untagged images. 1113 1114 ## import 1115 1116 Usage: docker import URL|- [REPOSITORY[:TAG]] 1117 1118 Create an empty filesystem image and import the contents of the tarball (.tar, .tar.gz, .tgz, .bzip, .tar.xz, .txz) into it, then optionally tag it. 1119 1120 URLs must start with `http` and point to a single file archive (.tar, 1121 .tar.gz, .tgz, .bzip, .tar.xz, or .txz) containing a root filesystem. If 1122 you would like to import from a local directory or archive, you can use 1123 the `-` parameter to take the data from `STDIN`. 1124 1125 #### Examples 1126 1127 **Import from a remote location:** 1128 1129 This will create a new untagged image. 1130 1131 $ sudo docker import http://example.com/exampleimage.tgz 1132 1133 **Import from a local file:** 1134 1135 Import to docker via pipe and `STDIN`. 1136 1137 $ cat exampleimage.tgz | sudo docker import - exampleimagelocal:new 1138 1139 **Import from a local directory:** 1140 1141 $ sudo tar -c . | sudo docker import - exampleimagedir 1142 1143 Note the `sudo` in this example – you must preserve 1144 the ownership of the files (especially root ownership) during the 1145 archiving with tar. If you are not root (or the sudo command) when you 1146 tar, then the ownerships might not get preserved. 1147 1148 ## info 1149 1150 1151 Usage: docker info 1152 1153 Display system-wide information 1154 1155 For example: 1156 1157 $ sudo docker -D info 1158 Containers: 14 1159 Images: 52 1160 Storage Driver: aufs 1161 Root Dir: /var/lib/docker/aufs 1162 Dirs: 545 1163 Execution Driver: native-0.2 1164 Kernel Version: 3.13.0-24-generic 1165 Operating System: Ubuntu 14.04 LTS 1166 CPUs: 1 1167 Name: prod-server-42 1168 ID: 7TRN:IPZB:QYBB:VPBQ:UMPP:KARE:6ZNR:XE6T:7EWV:PKF4:ZOJD:TPYS 1169 Total Memory: 2 GiB 1170 Debug mode (server): false 1171 Debug mode (client): true 1172 Fds: 10 1173 Goroutines: 9 1174 EventsListeners: 0 1175 Init Path: /usr/bin/docker 1176 Docker Root Dir: /var/lib/docker 1177 Username: svendowideit 1178 Registry: [https://index.docker.io/v1/] 1179 Labels: 1180 storage=ssd 1181 1182 The global `-D` option tells all `docker` commands to output debug information. 1183 1184 When sending issue reports, please use `docker version` and `docker -D info` to 1185 ensure we know how your setup is configured. 1186 1187 ## inspect 1188 1189 Usage: docker inspect [OPTIONS] CONTAINER|IMAGE [CONTAINER|IMAGE...] 1190 1191 Return low-level information on a container or image 1192 1193 -f, --format="" Format the output using the given go template. 1194 1195 By default, this will render all results in a JSON array. If a format is 1196 specified, the given template will be executed for each result. 1197 1198 Go's [text/template](http://golang.org/pkg/text/template/) package 1199 describes all the details of the format. 1200 1201 #### Examples 1202 1203 **Get an instance's IP address:** 1204 1205 For the most part, you can pick out any field from the JSON in a fairly 1206 straightforward manner. 1207 1208 $ sudo docker inspect --format='{{.NetworkSettings.IPAddress}}' $INSTANCE_ID 1209 1210 **Get an instance's MAC Address:** 1211 1212 For the most part, you can pick out any field from the JSON in a fairly 1213 straightforward manner. 1214 1215 $ sudo docker inspect --format='{{.NetworkSettings.MacAddress}}' $INSTANCE_ID 1216 1217 **List All Port Bindings:** 1218 1219 One can loop over arrays and maps in the results to produce simple text 1220 output: 1221 1222 $ sudo docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' $INSTANCE_ID 1223 1224 **Find a Specific Port Mapping:** 1225 1226 The `.Field` syntax doesn't work when the field name begins with a 1227 number, but the template language's `index` function does. The 1228 `.NetworkSettings.Ports` section contains a map of the internal port 1229 mappings to a list of external address/port objects, so to grab just the 1230 numeric public port, you use `index` to find the specific port map, and 1231 then `index` 0 contains the first object inside of that. Then we ask for 1232 the `HostPort` field to get the public address. 1233 1234 $ sudo docker inspect --format='{{(index (index .NetworkSettings.Ports "8787/tcp") 0).HostPort}}' $INSTANCE_ID 1235 1236 **Get config:** 1237 1238 The `.Field` syntax doesn't work when the field contains JSON data, but 1239 the template language's custom `json` function does. The `.config` 1240 section contains complex JSON object, so to grab it as JSON, you use 1241 `json` to convert the configuration object into JSON. 1242 1243 $ sudo docker inspect --format='{{json .config}}' $INSTANCE_ID 1244 1245 ## kill 1246 1247 Usage: docker kill [OPTIONS] CONTAINER [CONTAINER...] 1248 1249 Kill a running container using SIGKILL or a specified signal 1250 1251 -s, --signal="KILL" Signal to send to the container 1252 1253 The main process inside the container will be sent `SIGKILL`, or any 1254 signal specified with option `--signal`. 1255 1256 ## load 1257 1258 Usage: docker load [OPTIONS] 1259 1260 Load an image from a tar archive on STDIN 1261 1262 -i, --input="" Read from a tar archive file, instead of STDIN 1263 1264 Loads a tarred repository from a file or the standard input stream. 1265 Restores both images and tags. 1266 1267 $ sudo docker images 1268 REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE 1269 $ sudo docker load < busybox.tar 1270 $ sudo docker images 1271 REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE 1272 busybox latest 769b9341d937 7 weeks ago 2.489 MB 1273 $ sudo docker load --input fedora.tar 1274 $ sudo docker images 1275 REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE 1276 busybox latest 769b9341d937 7 weeks ago 2.489 MB 1277 fedora rawhide 0d20aec6529d 7 weeks ago 387 MB 1278 fedora 20 58394af37342 7 weeks ago 385.5 MB 1279 fedora heisenbug 58394af37342 7 weeks ago 385.5 MB 1280 fedora latest 58394af37342 7 weeks ago 385.5 MB 1281 1282 ## login 1283 1284 Usage: docker login [OPTIONS] [SERVER] 1285 1286 Register or log in to a Docker registry server, if no server is specified "https://index.docker.io/v1/" is the default. 1287 1288 -e, --email="" Email 1289 -p, --password="" Password 1290 -u, --username="" Username 1291 1292 If you want to login to a self-hosted registry you can specify this by 1293 adding the server name. 1294 1295 example: 1296 $ sudo docker login localhost:8080 1297 1298 ## logout 1299 1300 Usage: docker logout [SERVER] 1301 1302 Log out from a Docker registry, if no server is specified "https://index.docker.io/v1/" is the default. 1303 1304 For example: 1305 1306 $ sudo docker logout localhost:8080 1307 1308 ## logs 1309 1310 Usage: docker logs [OPTIONS] CONTAINER 1311 1312 Fetch the logs of a container 1313 1314 -f, --follow=false Follow log output 1315 -t, --timestamps=false Show timestamps 1316 --tail="all" Output the specified number of lines at the end of logs (defaults to all logs) 1317 1318 The `docker logs` command batch-retrieves logs present at the time of execution. 1319 1320 The `docker logs --follow` command will continue streaming the new output from 1321 the container's `STDOUT` and `STDERR`. 1322 1323 Passing a negative number or a non-integer to `--tail` is invalid and the 1324 value is set to `all` in that case. This behavior may change in the future. 1325 1326 The `docker logs --timestamp` commands will add an RFC3339Nano 1327 timestamp, for example `2014-09-16T06:17:46.000000000Z`, to each 1328 log entry. To ensure that the timestamps for are aligned the 1329 nano-second part of the timestamp will be padded with zero when necessary. 1330 1331 ## pause 1332 1333 Usage: docker pause CONTAINER 1334 1335 Pause all processes within a container 1336 1337 The `docker pause` command uses the cgroups freezer to suspend all processes in 1338 a container. Traditionally, when suspending a process the `SIGSTOP` signal is 1339 used, which is observable by the process being suspended. With the cgroups freezer 1340 the process is unaware, and unable to capture, that it is being suspended, 1341 and subsequently resumed. 1342 1343 See the 1344 [cgroups freezer documentation](https://www.kernel.org/doc/Documentation/cgroups/freezer-subsystem.txt) 1345 for further details. 1346 1347 ## port 1348 1349 Usage: docker port CONTAINER [PRIVATE_PORT[/PROTO]] 1350 1351 List port mappings for the CONTAINER, or lookup the public-facing port that is NAT-ed to the PRIVATE_PORT 1352 1353 You can find out all the ports mapped by not specifying a `PRIVATE_PORT`, or 1354 just a specific mapping: 1355 1356 $ sudo docker ps test 1357 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1358 b650456536c7 busybox:latest top 54 minutes ago Up 54 minutes 0.0.0.0:1234->9876/tcp, 0.0.0.0:4321->7890/tcp test 1359 $ sudo docker port test 1360 7890/tcp -> 0.0.0.0:4321 1361 9876/tcp -> 0.0.0.0:1234 1362 $ sudo docker port test 7890/tcp 1363 0.0.0.0:4321 1364 $ sudo docker port test 7890/udp 1365 2014/06/24 11:53:36 Error: No public port '7890/udp' published for test 1366 $ sudo docker port test 7890 1367 0.0.0.0:4321 1368 1369 ## pause 1370 1371 Usage: docker pause CONTAINER 1372 1373 Pause all processes within a container 1374 1375 The `docker pause` command uses the cgroups freezer to suspend all processes in 1376 a container. Traditionally when suspending a process the `SIGSTOP` signal is 1377 used, which is observable by the process being suspended. With the cgroups freezer 1378 the process is unaware, and unable to capture, that it is being suspended, 1379 and subsequently resumed. 1380 1381 See the 1382 [cgroups freezer documentation](https://www.kernel.org/doc/Documentation/cgroups/freezer-subsystem.txt) 1383 for further details. 1384 1385 ## rename 1386 1387 Usage: docker rename OLD_NAME NEW_NAME 1388 1389 rename a existing container to a NEW_NAME 1390 1391 The `docker rename` command allows the container to be renamed to a different name. 1392 1393 ## ps 1394 1395 Usage: docker ps [OPTIONS] 1396 1397 List containers 1398 1399 -a, --all=false Show all containers. Only running containers are shown by default. 1400 --before="" Show only container created before Id or Name, include non-running ones. 1401 -f, --filter=[] Provide filter values. Valid filters: 1402 exited=<int> - containers with exit code of <int> 1403 status=(restarting|running|paused|exited) 1404 -l, --latest=false Show only the latest created container, include non-running ones. 1405 -n=-1 Show n last created containers, include non-running ones. 1406 --no-trunc=false Don't truncate output 1407 -q, --quiet=false Only display numeric IDs 1408 -s, --size=false Display total file sizes 1409 --since="" Show only containers created since Id or Name, include non-running ones. 1410 1411 Running `docker ps` showing 2 linked containers. 1412 1413 $ sudo docker ps 1414 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1415 4c01db0b339c ubuntu:12.04 bash 17 seconds ago Up 16 seconds webapp 1416 d7886598dbe2 crosbymichael/redis:latest /redis-server --dir 33 minutes ago Up 33 minutes 6379/tcp redis,webapp/db 1417 1418 `docker ps` will show only running containers by default. To see all containers: 1419 `docker ps -a` 1420 1421 #### Filtering 1422 1423 The filtering flag (`-f` or `--filter)` format is a `key=value` pair. If there is more 1424 than one filter, then pass multiple flags (e.g. `--filter "foo=bar" --filter "bif=baz"`) 1425 1426 Current filters: 1427 * exited (int - the code of exited containers. Only useful with '--all') 1428 * status (restarting|running|paused|exited) 1429 1430 ##### Successfully exited containers 1431 1432 $ sudo docker ps -a --filter 'exited=0' 1433 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1434 ea09c3c82f6e registry:latest /srv/run.sh 2 weeks ago Exited (0) 2 weeks ago 127.0.0.1:5000->5000/tcp desperate_leakey 1435 106ea823fe4e fedora:latest /bin/sh -c 'bash -l' 2 weeks ago Exited (0) 2 weeks ago determined_albattani 1436 48ee228c9464 fedora:20 bash 2 weeks ago Exited (0) 2 weeks ago tender_torvalds 1437 1438 This shows all the containers that have exited with status of '0' 1439 1440 ## pull 1441 1442 Usage: docker pull [OPTIONS] NAME[:TAG] 1443 1444 Pull an image or a repository from the registry 1445 1446 -a, --all-tags=false Download all tagged images in the repository 1447 1448 Most of your images will be created on top of a base image from the 1449 [Docker Hub](https://hub.docker.com) registry. 1450 1451 [Docker Hub](https://hub.docker.com) contains many pre-built images that you 1452 can `pull` and try without needing to define and configure your own. 1453 1454 It is also possible to manually specify the path of a registry to pull from. 1455 For example, if you have set up a local registry, you can specify its path to 1456 pull from it. A repository path is similar to a URL, but does not contain 1457 a protocol specifier (`https://`, for example). 1458 1459 To download a particular image, or set of images (i.e., a repository), 1460 use `docker pull`: 1461 1462 $ sudo docker pull debian 1463 # will pull the debian:latest image, its intermediate layers 1464 # and any aliases of the same id 1465 $ sudo docker pull debian:testing 1466 # will pull the image named debian:testing and any intermediate 1467 # layers it is based on. 1468 # (Typically the empty `scratch` image, a MAINTAINER layer, 1469 # and the un-tarred base). 1470 $ sudo docker pull --all-tags centos 1471 # will pull all the images from the centos repository 1472 $ sudo docker pull registry.hub.docker.com/debian 1473 # manually specifies the path to the default Docker registry. This could 1474 # be replaced with the path to a local registry to pull from another source. 1475 1476 ## push 1477 1478 Usage: docker push NAME[:TAG] 1479 1480 Push an image or a repository to the registry 1481 1482 Use `docker push` to share your images to the [Docker Hub](https://hub.docker.com) 1483 registry or to a self-hosted one. 1484 1485 ## restart 1486 1487 Usage: docker restart [OPTIONS] CONTAINER [CONTAINER...] 1488 1489 Restart a running container 1490 1491 -t, --time=10 Number of seconds to try to stop for before killing the container. Once killed it will then be restarted. Default is 10 seconds. 1492 1493 ## rm 1494 1495 Usage: docker rm [OPTIONS] CONTAINER [CONTAINER...] 1496 1497 Remove one or more containers 1498 1499 -f, --force=false Force the removal of a running container (uses SIGKILL) 1500 -l, --link=false Remove the specified link and not the underlying container 1501 -v, --volumes=false Remove the volumes associated with the container 1502 1503 #### Examples 1504 1505 $ sudo docker rm /redis 1506 /redis 1507 1508 This will remove the container referenced under the link 1509 `/redis`. 1510 1511 $ sudo docker rm --link /webapp/redis 1512 /webapp/redis 1513 1514 This will remove the underlying link between `/webapp` and the `/redis` 1515 containers removing all network communication. 1516 1517 $ sudo docker rm --force redis 1518 redis 1519 1520 The main process inside the container referenced under the link `/redis` will receive 1521 `SIGKILL`, then the container will be removed. 1522 1523 This command will delete all stopped containers. The command `docker ps 1524 -a -q` will return all existing container IDs and pass them to the `rm` 1525 command which will delete them. Any running containers will not be 1526 deleted. 1527 1528 ## rmi 1529 1530 Usage: docker rmi [OPTIONS] IMAGE [IMAGE...] 1531 1532 Remove one or more images 1533 1534 -f, --force=false Force removal of the image 1535 --no-prune=false Do not delete untagged parents 1536 1537 #### Removing tagged images 1538 1539 Images can be removed either by their short or long IDs, or their image 1540 names. If an image has more than one name, each of them needs to be 1541 removed before the image is removed. 1542 1543 $ sudo docker images 1544 REPOSITORY TAG IMAGE ID CREATED SIZE 1545 test1 latest fd484f19954f 23 seconds ago 7 B (virtual 4.964 MB) 1546 test latest fd484f19954f 23 seconds ago 7 B (virtual 4.964 MB) 1547 test2 latest fd484f19954f 23 seconds ago 7 B (virtual 4.964 MB) 1548 1549 $ sudo docker rmi fd484f19954f 1550 Error: Conflict, cannot delete image fd484f19954f because it is tagged in multiple repositories 1551 2013/12/11 05:47:16 Error: failed to remove one or more images 1552 1553 $ sudo docker rmi test1 1554 Untagged: fd484f19954f4920da7ff372b5067f5b7ddb2fd3830cecd17b96ea9e286ba5b8 1555 $ sudo docker rmi test2 1556 Untagged: fd484f19954f4920da7ff372b5067f5b7ddb2fd3830cecd17b96ea9e286ba5b8 1557 1558 $ sudo docker images 1559 REPOSITORY TAG IMAGE ID CREATED SIZE 1560 test latest fd484f19954f 23 seconds ago 7 B (virtual 4.964 MB) 1561 $ sudo docker rmi test 1562 Untagged: fd484f19954f4920da7ff372b5067f5b7ddb2fd3830cecd17b96ea9e286ba5b8 1563 Deleted: fd484f19954f4920da7ff372b5067f5b7ddb2fd3830cecd17b96ea9e286ba5b8 1564 1565 ## run 1566 1567 Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...] 1568 1569 Run a command in a new container 1570 1571 -a, --attach=[] Attach to STDIN, STDOUT or STDERR. 1572 --add-host=[] Add a custom host-to-IP mapping (host:ip) 1573 -c, --cpu-shares=0 CPU shares (relative weight) 1574 --cap-add=[] Add Linux capabilities 1575 --cap-drop=[] Drop Linux capabilities 1576 --cidfile="" Write the container ID to the file 1577 --cpuset="" CPUs in which to allow execution (0-3, 0,1) 1578 -d, --detach=false Detached mode: run the container in the background and print the new container ID 1579 --device=[] Add a host device to the container (e.g. --device=/dev/sdc:/dev/xvdc:rwm) 1580 --dns=[] Set custom DNS servers 1581 --dns-search=[] Set custom DNS search domains (Use --dns-search=. if you don't wish to set the search domain) 1582 -e, --env=[] Set environment variables 1583 --entrypoint="" Overwrite the default ENTRYPOINT of the image 1584 --env-file=[] Read in a line delimited file of environment variables 1585 --expose=[] Expose a port or a range of ports (e.g. --expose=3300-3310) from the container without publishing it to your host 1586 -h, --hostname="" Container host name 1587 -i, --interactive=false Keep STDIN open even if not attached 1588 --ipc="" Default is to create a private IPC namespace (POSIX SysV IPC) for the container 1589 'container:<name|id>': reuses another container shared memory, semaphores and message queues 1590 'host': use the host shared memory,semaphores and message queues inside the container. Note: the host mode gives the container full access to local shared memory and is therefore considered insecure. 1591 --link=[] Add link to another container in the form of name:alias 1592 --lxc-conf=[] (lxc exec-driver only) Add custom lxc options --lxc-conf="lxc.cgroup.cpuset.cpus = 0,1" 1593 -m, --memory="" Memory limit (format: <number><optional unit>, where unit = b, k, m or g) 1594 --mac-address="" Container MAC address (e.g. 92:d0:c6:0a:29:33) 1595 --name="" Assign a name to the container 1596 --net="bridge" Set the Network mode for the container 1597 'bridge': creates a new network stack for the container on the docker bridge 1598 'none': no networking for this container 1599 'container:<name|id>': reuses another container network stack 1600 'host': use the host network stack inside the container. Note: the host mode gives the container full access to local system services such as D-bus and is therefore considered insecure. 1601 -P, --publish-all=false Publish all exposed ports to random ports on the host interfaces 1602 -p, --publish=[] Publish a container's port to the host 1603 format: ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort | containerPort 1604 Both hostPort and containerPort can be specified as a range of ports. 1605 When specifying ranges for both, the number of container ports in the range must match the number of host ports in the range. (e.g., `-p 1234-1236:1234-1236/tcp`) 1606 (use 'docker port' to see the actual mapping) 1607 --pid=host 'host': use the host PID namespace inside the container. Note: the host mode gives the container full access to local system services such as D-bus and is therefore considered insecure. 1608 --privileged=false Give extended privileges to this container 1609 --restart="" Restart policy to apply when a container exits (no, on-failure[:max-retry], always) 1610 --rm=false Automatically remove the container when it exits (incompatible with -d) 1611 --security-opt=[] Security Options 1612 --sig-proxy=true Proxy received signals to the process (non-TTY mode only). SIGCHLD, SIGSTOP, and SIGKILL are not proxied. 1613 -t, --tty=false Allocate a pseudo-TTY 1614 -u, --user="" Username or UID 1615 -v, --volume=[] Bind mount a volume (e.g., from the host: -v /host:/container, from Docker: -v /container) 1616 --volumes-from=[] Mount volumes from the specified container(s) 1617 -w, --workdir="" Working directory inside the container 1618 1619 The `docker run` command first `creates` a writeable container layer over the 1620 specified image, and then `starts` it using the specified command. That is, 1621 `docker run` is equivalent to the API `/containers/create` then 1622 `/containers/(id)/start`. A stopped container can be restarted with all its 1623 previous changes intact using `docker start`. See `docker ps -a` to view a list 1624 of all containers. 1625 1626 There is detailed information about `docker run` in the [Docker run reference]( 1627 /reference/run/). 1628 1629 The `docker run` command can be used in combination with `docker commit` to 1630 [*change the command that a container runs*](#commit-an-existing-container). 1631 1632 See the [Docker User Guide](/userguide/dockerlinks/) for more detailed 1633 information about the `--expose`, `-p`, `-P` and `--link` parameters, 1634 and linking containers. 1635 1636 #### Examples 1637 1638 $ sudo docker run --cidfile /tmp/docker_test.cid ubuntu echo "test" 1639 1640 This will create a container and print `test` to the console. The `cidfile` 1641 flag makes Docker attempt to create a new file and write the container ID to it. 1642 If the file exists already, Docker will return an error. Docker will close this 1643 file when `docker run` exits. 1644 1645 $ sudo docker run -t -i --rm ubuntu bash 1646 root@bc338942ef20:/# mount -t tmpfs none /mnt 1647 mount: permission denied 1648 1649 This will *not* work, because by default, most potentially dangerous kernel 1650 capabilities are dropped; including `cap_sys_admin` (which is required to mount 1651 filesystems). However, the `--privileged` flag will allow it to run: 1652 1653 $ sudo docker run --privileged ubuntu bash 1654 root@50e3f57e16e6:/# mount -t tmpfs none /mnt 1655 root@50e3f57e16e6:/# df -h 1656 Filesystem Size Used Avail Use% Mounted on 1657 none 1.9G 0 1.9G 0% /mnt 1658 1659 The `--privileged` flag gives *all* capabilities to the container, and it also 1660 lifts all the limitations enforced by the `device` cgroup controller. In other 1661 words, the container can then do almost everything that the host can do. This 1662 flag exists to allow special use-cases, like running Docker within Docker. 1663 1664 $ sudo docker run -w /path/to/dir/ -i -t ubuntu pwd 1665 1666 The `-w` lets the command being executed inside directory given, here 1667 `/path/to/dir/`. If the path does not exists it is created inside the container. 1668 1669 $ sudo docker run -v `pwd`:`pwd` -w `pwd` -i -t ubuntu pwd 1670 1671 The `-v` flag mounts the current working directory into the container. The `-w` 1672 lets the command being executed inside the current working directory, by 1673 changing into the directory to the value returned by `pwd`. So this 1674 combination executes the command using the container, but inside the 1675 current working directory. 1676 1677 $ sudo docker run -v /doesnt/exist:/foo -w /foo -i -t ubuntu bash 1678 1679 When the host directory of a bind-mounted volume doesn't exist, Docker 1680 will automatically create this directory on the host for you. In the 1681 example above, Docker will create the `/doesnt/exist` 1682 folder before starting your container. 1683 1684 $ sudo docker run -t -i -v /var/run/docker.sock:/var/run/docker.sock -v ./static-docker:/usr/bin/docker busybox sh 1685 1686 By bind-mounting the docker unix socket and statically linked docker 1687 binary (such as that provided by [https://get.docker.com]( 1688 https://get.docker.com)), you give the container the full access to create and 1689 manipulate the host's Docker daemon. 1690 1691 $ sudo docker run -p 127.0.0.1:80:8080 ubuntu bash 1692 1693 This binds port `8080` of the container to port `80` on `127.0.0.1` of 1694 the host machine. The [Docker User Guide](/userguide/dockerlinks/) 1695 explains in detail how to manipulate ports in Docker. 1696 1697 $ sudo docker run --expose 80 ubuntu bash 1698 1699 This exposes port `80` of the container for use within a link without 1700 publishing the port to the host system's interfaces. The [Docker User 1701 Guide](/userguide/dockerlinks) explains in detail how to manipulate 1702 ports in Docker. 1703 1704 $ sudo docker run -e MYVAR1 --env MYVAR2=foo --env-file ./env.list ubuntu bash 1705 1706 This sets environmental variables in the container. For illustration all three 1707 flags are shown here. Where `-e`, `--env` take an environment variable and 1708 value, or if no "=" is provided, then that variable's current value is passed 1709 through (i.e. `$MYVAR1` from the host is set to `$MYVAR1` in the container). All 1710 three flags, `-e`, `--env` and `--env-file` can be repeated. 1711 1712 Regardless of the order of these three flags, the `--env-file` are processed 1713 first, and then `-e`, `--env` flags. This way, the `-e` or `--env` will 1714 override variables as needed. 1715 1716 $ cat ./env.list 1717 TEST_FOO=BAR 1718 $ sudo docker run --env TEST_FOO="This is a test" --env-file ./env.list busybox env | grep TEST_FOO 1719 TEST_FOO=This is a test 1720 1721 The `--env-file` flag takes a filename as an argument and expects each line 1722 to be in the `VAR=VAL` format, mimicking the argument passed to `--env`. Comment 1723 lines need only be prefixed with `#` 1724 1725 An example of a file passed with `--env-file` 1726 1727 $ cat ./env.list 1728 TEST_FOO=BAR 1729 1730 # this is a comment 1731 TEST_APP_DEST_HOST=10.10.0.127 1732 TEST_APP_DEST_PORT=8888 1733 1734 # pass through this variable from the caller 1735 TEST_PASSTHROUGH 1736 $ sudo TEST_PASSTHROUGH=howdy docker run --env-file ./env.list busybox env 1737 HOME=/ 1738 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 1739 HOSTNAME=5198e0745561 1740 TEST_FOO=BAR 1741 TEST_APP_DEST_HOST=10.10.0.127 1742 TEST_APP_DEST_PORT=8888 1743 TEST_PASSTHROUGH=howdy 1744 1745 $ sudo docker run --name console -t -i ubuntu bash 1746 1747 This will create and run a new container with the container name being 1748 `console`. 1749 1750 $ sudo docker run --link /redis:redis --name console ubuntu bash 1751 1752 The `--link` flag will link the container named `/redis` into the newly 1753 created container with the alias `redis`. The new container can access the 1754 network and environment of the `redis` container via environment variables. 1755 The `--name` flag will assign the name `console` to the newly created 1756 container. 1757 1758 $ sudo docker run --volumes-from 777f7dc92da7 --volumes-from ba8c0c54f0f2:ro -i -t ubuntu pwd 1759 1760 The `--volumes-from` flag mounts all the defined volumes from the referenced 1761 containers. Containers can be specified by repetitions of the `--volumes-from` 1762 argument. The container ID may be optionally suffixed with `:ro` or `:rw` to 1763 mount the volumes in read-only or read-write mode, respectively. By default, 1764 the volumes are mounted in the same mode (read write or read only) as 1765 the reference container. 1766 1767 The `-a` flag tells `docker run` to bind to the container's `STDIN`, `STDOUT` or 1768 `STDERR`. This makes it possible to manipulate the output and input as needed. 1769 1770 $ echo "test" | sudo docker run -i -a stdin ubuntu cat - 1771 1772 This pipes data into a container and prints the container's ID by attaching 1773 only to the container's `STDIN`. 1774 1775 $ sudo docker run -a stderr ubuntu echo test 1776 1777 This isn't going to print anything unless there's an error because we've 1778 only attached to the `STDERR` of the container. The container's logs 1779 still store what's been written to `STDERR` and `STDOUT`. 1780 1781 $ cat somefile | sudo docker run -i -a stdin mybuilder dobuild 1782 1783 This is how piping a file into a container could be done for a build. 1784 The container's ID will be printed after the build is done and the build 1785 logs could be retrieved using `docker logs`. This is 1786 useful if you need to pipe a file or something else into a container and 1787 retrieve the container's ID once the container has finished running. 1788 1789 $ sudo docker run --device=/dev/sdc:/dev/xvdc --device=/dev/sdd --device=/dev/zero:/dev/nulo -i -t ubuntu ls -l /dev/{xvdc,sdd,nulo} 1790 brw-rw---- 1 root disk 8, 2 Feb 9 16:05 /dev/xvdc 1791 brw-rw---- 1 root disk 8, 3 Feb 9 16:05 /dev/sdd 1792 crw-rw-rw- 1 root root 1, 5 Feb 9 16:05 /dev/nulo 1793 1794 It is often necessary to directly expose devices to a container. The `--device` 1795 option enables that. For example, a specific block storage device or loop 1796 device or audio device can be added to an otherwise unprivileged container 1797 (without the `--privileged` flag) and have the application directly access it. 1798 1799 By default, the container will be able to `read`, `write` and `mknod` these devices. 1800 This can be overridden using a third `:rwm` set of options to each `--device` 1801 flag: 1802 1803 1804 ``` 1805 $ sudo docker run --device=/dev/sda:/dev/xvdc --rm -it ubuntu fdisk /dev/xvdc 1806 1807 Command (m for help): q 1808 $ sudo docker run --device=/dev/sda:/dev/xvdc:r --rm -it ubuntu fdisk /dev/xvdc 1809 You will not be able to write the partition table. 1810 1811 Command (m for help): q 1812 1813 $ sudo docker run --device=/dev/sda:/dev/xvdc --rm -it ubuntu fdisk /dev/xvdc 1814 1815 Command (m for help): q 1816 1817 $ sudo docker run --device=/dev/sda:/dev/xvdc:m --rm -it ubuntu fdisk /dev/xvdc 1818 fdisk: unable to open /dev/xvdc: Operation not permitted 1819 ``` 1820 1821 **Note:** 1822 > `--device` cannot be safely used with ephemeral devices. Block devices that 1823 > may be removed should not be added to untrusted containers with `--device`. 1824 1825 **A complete example:** 1826 1827 $ sudo docker run -d --name static static-web-files sh 1828 $ sudo docker run -d --expose=8098 --name riak riakserver 1829 $ sudo docker run -d -m 100m -e DEVELOPMENT=1 -e BRANCH=example-code -v $(pwd):/app/bin:ro --name app appserver 1830 $ sudo docker run -d -p 1443:443 --dns=10.0.0.1 --dns-search=dev.org -v /var/log/httpd --volumes-from static --link riak --link app -h www.sven.dev.org --name web webserver 1831 $ sudo docker run -t -i --rm --volumes-from web -w /var/log/httpd busybox tail -f access.log 1832 1833 This example shows five containers that might be set up to test a web 1834 application change: 1835 1836 1. Start a pre-prepared volume image `static-web-files` (in the background) 1837 that has CSS, image and static HTML in it, (with a `VOLUME` instruction in 1838 the Dockerfile to allow the web server to use those files); 1839 2. Start a pre-prepared `riakserver` image, give the container name `riak` and 1840 expose port `8098` to any containers that link to it; 1841 3. Start the `appserver` image, restricting its memory usage to 100MB, setting 1842 two environment variables `DEVELOPMENT` and `BRANCH` and bind-mounting the 1843 current directory (`$(pwd)`) in the container in read-only mode as `/app/bin`; 1844 4. Start the `webserver`, mapping port `443` in the container to port `1443` on 1845 the Docker server, setting the DNS server to `10.0.0.1` and DNS search 1846 domain to `dev.org`, creating a volume to put the log files into (so we can 1847 access it from another container), then importing the files from the volume 1848 exposed by the `static` container, and linking to all exposed ports from 1849 `riak` and `app`. Lastly, we set the hostname to `web.sven.dev.org` so its 1850 consistent with the pre-generated SSL certificate; 1851 5. Finally, we create a container that runs `tail -f access.log` using the logs 1852 volume from the `web` container, setting the workdir to `/var/log/httpd`. The 1853 `--rm` option means that when the container exits, the container's layer is 1854 removed. 1855 1856 #### Restart Policies 1857 1858 Using the `--restart` flag on Docker run you can specify a restart policy for 1859 how a container should or should not be restarted on exit. 1860 1861 An ever increasing delay (double the previous delay, starting at 100 milliseconds) 1862 is added before each restart to prevent flooding the server. This means the daemaon 1863 will wait for 100 mS, then 200 mS, 400, 800, 1600, and so on until either the 1864 `on-failure` limit is hit, or when you `docker stop` or even `docker rm -f` 1865 the container. 1866 1867 When a restart policy is active on a container, it will be shown in `docker ps` 1868 as either `Up` or `Restarting` in `docker ps`. It can also be useful to use 1869 `docker events` to see the restart policy in effect. 1870 1871 ** no ** - Do not restart the container when it exits. 1872 1873 ** on-failure ** - Restart the container only if it exits with a non zero exit status. 1874 1875 ** always ** - Always restart the container regardless of the exit status. 1876 1877 You can also specify the maximum amount of times Docker will try to 1878 restart the container when using the ** on-failure ** policy. The 1879 default is that Docker will try forever to restart the container. 1880 1881 $ sudo docker run --restart=always redis 1882 1883 This will run the `redis` container with a restart policy of ** always ** so that if 1884 the container exits, Docker will restart it. 1885 1886 $ sudo docker run --restart=on-failure:10 redis 1887 1888 This will run the `redis` container with a restart policy of ** 1889 on-failure ** and a maximum restart count of 10. If the `redis` 1890 container exits with a non-zero exit status more than 10 times in a row 1891 Docker will abort trying to restart the container. Providing a maximum 1892 restart limit is only valid for the ** on-failure ** policy. 1893 1894 ### Adding entries to a container hosts file 1895 1896 You can add other hosts into a container's `/etc/hosts` file by using one or more 1897 `--add-host` flags. This example adds a static address for a host named `docker`: 1898 1899 ``` 1900 $ docker run --add-host=docker:10.180.0.1 --rm -it debian 1901 $$ ping docker 1902 PING docker (10.180.0.1): 48 data bytes 1903 56 bytes from 10.180.0.1: icmp_seq=0 ttl=254 time=7.600 ms 1904 56 bytes from 10.180.0.1: icmp_seq=1 ttl=254 time=30.705 ms 1905 ^C--- docker ping statistics --- 1906 2 packets transmitted, 2 packets received, 0% packet loss 1907 round-trip min/avg/max/stddev = 7.600/19.152/30.705/11.553 ms 1908 ``` 1909 1910 > **Note:** 1911 > Sometimes you need to connect to the Docker host, which means getting the IP 1912 > address of the host. You can use the following shell commands to simplify this 1913 > process: 1914 > 1915 > $ alias hostip="ip route show 0.0.0.0/0 | grep -Eo 'via \S+' | awk '{ print \$2 }'" 1916 > $ docker run --add-host=docker:$(hostip) --rm -it debian 1917 1918 ## save 1919 1920 Usage: docker save [OPTIONS] IMAGE [IMAGE...] 1921 1922 Save an image(s) to a tar archive (streamed to STDOUT by default) 1923 1924 -o, --output="" Write to a file, instead of STDOUT 1925 1926 Produces a tarred repository to the standard output stream. 1927 Contains all parent layers, and all tags + versions, or specified `repo:tag`, for 1928 each argument provided. 1929 1930 It is used to create a backup that can then be used with `docker load` 1931 1932 $ sudo docker save busybox > busybox.tar 1933 $ ls -sh busybox.tar 1934 2.7M busybox.tar 1935 $ sudo docker save --output busybox.tar busybox 1936 $ ls -sh busybox.tar 1937 2.7M busybox.tar 1938 $ sudo docker save -o fedora-all.tar fedora 1939 $ sudo docker save -o fedora-latest.tar fedora:latest 1940 1941 It is even useful to cherry-pick particular tags of an image repository 1942 1943 $ sudo docker save -o ubuntu.tar ubuntu:lucid ubuntu:saucy 1944 1945 ## search 1946 1947 Search [Docker Hub](https://hub.docker.com) for images 1948 1949 Usage: docker search [OPTIONS] TERM 1950 1951 Search the Docker Hub for images 1952 1953 --automated=false Only show automated builds 1954 --no-trunc=false Don't truncate output 1955 -s, --stars=0 Only displays with at least x stars 1956 1957 See [*Find Public Images on Docker Hub*]( 1958 /userguide/dockerrepos/#searching-for-images) for 1959 more details on finding shared images from the command line. 1960 1961 ## start 1962 1963 Usage: docker start [OPTIONS] CONTAINER [CONTAINER...] 1964 1965 Restart a stopped container 1966 1967 -a, --attach=false Attach container's STDOUT and STDERR and forward all signals to the process 1968 -i, --interactive=false Attach container's STDIN 1969 1970 When run on a container that has already been started, 1971 takes no action and succeeds unconditionally. 1972 1973 ## stop 1974 1975 Usage: docker stop [OPTIONS] CONTAINER [CONTAINER...] 1976 1977 Stop a running container by sending SIGTERM and then SIGKILL after a grace period 1978 1979 -t, --time=10 Number of seconds to wait for the container to stop before killing it. Default is 10 seconds. 1980 1981 The main process inside the container will receive `SIGTERM`, and after a 1982 grace period, `SIGKILL`. 1983 1984 ## tag 1985 1986 Usage: docker tag [OPTIONS] IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG] 1987 1988 Tag an image into a repository 1989 1990 -f, --force=false Force 1991 1992 You can group your images together using names and tags, and then upload 1993 them to [*Share Images via Repositories*]( 1994 /userguide/dockerrepos/#contributing-to-docker-hub). 1995 1996 ## top 1997 1998 Usage: docker top CONTAINER [ps OPTIONS] 1999 2000 Display the running processes of a container 2001 2002 ## unpause 2003 2004 Usage: docker unpause CONTAINER 2005 2006 Unpause all processes within a container 2007 2008 The `docker unpause` command uses the cgroups freezer to un-suspend all 2009 processes in a container. 2010 2011 See the 2012 [cgroups freezer documentation](https://www.kernel.org/doc/Documentation/cgroups/freezer-subsystem.txt) 2013 for further details. 2014 2015 ## version 2016 2017 Usage: docker version 2018 2019 Show the Docker version information. 2020 2021 Show the Docker version, API version, Git commit, and Go version of 2022 both Docker client and daemon. 2023 2024 ## wait 2025 2026 Usage: docker wait CONTAINER [CONTAINER...] 2027 2028 Block until a container stops, then print its exit code. 2029