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