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