github.com/olljanat/moby@v1.13.1/docs/reference/commandline/cli.md (about)

     1  ---
     2  title: "Use the Docker command line"
     3  description: "Docker's CLI command description and usage"
     4  keywords: "Docker, Docker documentation, CLI, command line"
     5  ---
     6  
     7  <!-- This file is maintained within the docker/docker Github
     8       repository at https://github.com/docker/docker/. Make all
     9       pull requests against that repo. If you see this file in
    10       another repository, consider it read-only there, as it will
    11       periodically be overwritten by the definitive file. Pull
    12       requests which include edits to this file in other repositories
    13       will be rejected.
    14  -->
    15  
    16  # Use the Docker command line
    17  
    18  To list available commands, either run `docker` with no parameters
    19  or execute `docker help`:
    20  
    21  ```bash
    22  $ docker
    23  Usage: docker [OPTIONS] COMMAND [ARG...]
    24         docker [ --help | -v | --version ]
    25  
    26  A self-sufficient runtime for containers.
    27  
    28  Options:
    29        --config string      Location of client config files (default "/root/.docker")
    30    -D, --debug              Enable debug mode
    31        --help               Print usage
    32    -H, --host value         Daemon socket(s) to connect to (default [])
    33    -l, --log-level string   Set the logging level ("debug", "info", "warn", "error", "fatal") (default "info")
    34        --tls                Use TLS; implied by --tlsverify
    35        --tlscacert string   Trust certs signed only by this CA (default "/root/.docker/ca.pem")
    36        --tlscert string     Path to TLS certificate file (default "/root/.docker/cert.pem")
    37        --tlskey string      Path to TLS key file (default "/root/.docker/key.pem")
    38        --tlsverify          Use TLS and verify the remote
    39    -v, --version            Print version information and quit
    40  
    41  Commands:
    42      attach    Attach to a running container
    43      # […]
    44  ```
    45  
    46  Depending on your Docker system configuration, you may be required to preface
    47  each `docker` command with `sudo`. To avoid having to use `sudo` with the
    48  `docker` command, your system administrator can create a Unix group called
    49  `docker` and add users to it.
    50  
    51  For more information about installing Docker or `sudo` configuration, refer to
    52  the [installation](https://docs.docker.com/engine/installation/) instructions for your operating system.
    53  
    54  ## Environment variables
    55  
    56  For easy reference, the following list of environment variables are supported
    57  by the `docker` command line:
    58  
    59  * `DOCKER_API_VERSION` The API version to use (e.g. `1.19`)
    60  * `DOCKER_CONFIG` The location of your client configuration files.
    61  * `DOCKER_CERT_PATH` The location of your authentication keys.
    62  * `DOCKER_DRIVER` The graph driver to use.
    63  * `DOCKER_HOST` Daemon socket to connect to.
    64  * `DOCKER_NOWARN_KERNEL_VERSION` Prevent warnings that your Linux kernel is
    65    unsuitable for Docker.
    66  * `DOCKER_RAMDISK` If set this will disable 'pivot_root'.
    67  * `DOCKER_TLS_VERIFY` When set Docker uses TLS and verifies the remote.
    68  * `DOCKER_CONTENT_TRUST` When set Docker uses notary to sign and verify images.
    69    Equates to `--disable-content-trust=false` for build, create, pull, push, run.
    70  * `DOCKER_CONTENT_TRUST_SERVER` The URL of the Notary server to use. This defaults
    71    to the same URL as the registry.
    72  * `DOCKER_HIDE_LEGACY_COMMANDS` When set, Docker hides "legacy" top-level commands (such as `docker rm`, and 
    73    `docker pull`) in `docker help` output, and only `Management commands` per object-type (e.g., `docker container`) are
    74    printed. This may become the default in a future release, at which point this environment-variable is removed.
    75  * `DOCKER_TMPDIR` Location for temporary Docker files.
    76  
    77  Because Docker is developed using Go, you can also use any environment
    78  variables used by the Go runtime. In particular, you may find these useful:
    79  
    80  * `HTTP_PROXY`
    81  * `HTTPS_PROXY`
    82  * `NO_PROXY`
    83  
    84  These Go environment variables are case-insensitive. See the
    85  [Go specification](http://golang.org/pkg/net/http/) for details on these
    86  variables.
    87  
    88  ## Configuration files
    89  
    90  By default, the Docker command line stores its configuration files in a
    91  directory called `.docker` within your `$HOME` directory. However, you can
    92  specify a different location via the `DOCKER_CONFIG` environment variable
    93  or the `--config` command line option. If both are specified, then the
    94  `--config` option overrides the `DOCKER_CONFIG` environment variable.
    95  For example:
    96  
    97      docker --config ~/testconfigs/ ps
    98  
    99  Instructs Docker to use the configuration files in your `~/testconfigs/`
   100  directory when running the `ps` command.
   101  
   102  Docker manages most of the files in the configuration directory
   103  and you should not modify them. However, you *can modify* the
   104  `config.json` file to control certain aspects of how the `docker`
   105  command behaves.
   106  
   107  Currently, you can modify the `docker` command behavior using environment
   108  variables or command-line options. You can also use options within
   109  `config.json` to modify some of the same behavior. When using these
   110  mechanisms, you must keep in mind the order of precedence among them. Command
   111  line options override environment variables and environment variables override
   112  properties you specify in a `config.json` file.
   113  
   114  The `config.json` file stores a JSON encoding of several properties:
   115  
   116  The property `HttpHeaders` specifies a set of headers to include in all messages
   117  sent from the Docker client to the daemon. Docker does not try to interpret or
   118  understand these header; it simply puts them into the messages. Docker does
   119  not allow these headers to change any headers it sets for itself.
   120  
   121  The property `psFormat` specifies the default format for `docker ps` output.
   122  When the `--format` flag is not provided with the `docker ps` command,
   123  Docker's client uses this property. If this property is not set, the client
   124  falls back to the default table format. For a list of supported formatting
   125  directives, see the
   126  [**Formatting** section in the `docker ps` documentation](ps.md)
   127  
   128  The property `imagesFormat` specifies the default format for `docker images` output.
   129  When the `--format` flag is not provided with the `docker images` command,
   130  Docker's client uses this property. If this property is not set, the client
   131  falls back to the default table format. For a list of supported formatting
   132  directives, see the [**Formatting** section in the `docker images` documentation](images.md)
   133  
   134  The property `serviceInspectFormat` specifies the default format for `docker
   135  service inspect` output. When the `--format` flag is not provided with the
   136  `docker service inspect` command, Docker's client uses this property. If this
   137  property is not set, the client falls back to the default json format. For a
   138  list of supported formatting directives, see the
   139  [**Formatting** section in the `docker service inspect` documentation](service_inspect.md)
   140  
   141  The property `statsFormat` specifies the default format for `docker
   142  stats` output. When the `--format` flag is not provided with the
   143  `docker stats` command, Docker's client uses this property. If this
   144  property is not set, the client falls back to the default table
   145  format. For a list of supported formatting directives, see
   146  [**Formatting** section in the `docker stats` documentation](stats.md)
   147  
   148  Once attached to a container, users detach from it and leave it running using
   149  the using `CTRL-p CTRL-q` key sequence. This detach key sequence is customizable
   150  using the `detachKeys` property. Specify a `<sequence>` value for the
   151  property. The format of the `<sequence>` is a comma-separated list of either
   152  a letter [a-Z], or the `ctrl-` combined with any of the following:
   153  
   154  * `a-z` (a single lowercase alpha character )
   155  * `@` (at sign)
   156  * `[` (left bracket)
   157  * `\\` (two backward slashes)
   158  *  `_` (underscore)
   159  * `^` (caret)
   160  
   161  Your customization applies to all containers started in with your Docker client.
   162  Users can override your custom or the default key sequence on a per-container
   163  basis. To do this, the user specifies the `--detach-keys` flag with the `docker
   164  attach`, `docker exec`, `docker run` or `docker start` command.
   165  
   166  Following is a sample `config.json` file:
   167  
   168      {% raw %}
   169      {
   170        "HttpHeaders": {
   171          "MyHeader": "MyValue"
   172        },
   173        "psFormat": "table {{.ID}}\\t{{.Image}}\\t{{.Command}}\\t{{.Labels}}",
   174        "imagesFormat": "table {{.ID}}\\t{{.Repository}}\\t{{.Tag}}\\t{{.CreatedAt}}",
   175        "statsFormat": "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}",
   176        "serviceInspectFormat": "pretty",
   177        "detachKeys": "ctrl-e,e"
   178      }
   179      {% endraw %}
   180  
   181  ### Notary
   182  
   183  If using your own notary server and a self-signed certificate or an internal
   184  Certificate Authority, you need to place the certificate at
   185  `tls/<registry_url>/ca.crt` in your docker config directory.
   186  
   187  Alternatively you can trust the certificate globally by adding it to your system's
   188  list of root Certificate Authorities.
   189  
   190  ## Help
   191  
   192  To list the help on any command just execute the command, followed by the
   193  `--help` option.
   194  
   195      $ docker run --help
   196  
   197      Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
   198  
   199      Run a command in a new container
   200  
   201      Options:
   202            --add-host value             Add a custom host-to-IP mapping (host:ip) (default [])
   203        -a, --attach value               Attach to STDIN, STDOUT or STDERR (default [])
   204      ...
   205  
   206  ## Option types
   207  
   208  Single character command line options can be combined, so rather than
   209  typing `docker run -i -t --name test busybox sh`,
   210  you can write `docker run -it --name test busybox sh`.
   211  
   212  ### Boolean
   213  
   214  Boolean options take the form `-d=false`. The value you see in the help text is
   215  the default value which is set if you do **not** specify that flag. If you
   216  specify a Boolean flag without a value, this will set the flag to `true`,
   217  irrespective of the default value.
   218  
   219  For example, running `docker run -d` will set the value to `true`, so your
   220  container **will** run in "detached" mode, in the background.
   221  
   222  Options which default to `true` (e.g., `docker build --rm=true`) can only be
   223  set to the non-default value by explicitly setting them to `false`:
   224  
   225      $ docker build --rm=false .
   226  
   227  ### Multi
   228  
   229  You can specify options like `-a=[]` multiple times in a single command line,
   230  for example in these commands:
   231  
   232      $ docker run -a stdin -a stdout -i -t ubuntu /bin/bash
   233      $ docker run -a stdin -a stdout -a stderr ubuntu /bin/ls
   234  
   235  Sometimes, multiple options can call for a more complex value string as for
   236  `-v`:
   237  
   238      $ docker run -v /host:/container example/mysql
   239  
   240  > **Note:**
   241  > Do not use the `-t` and `-a stderr` options together due to
   242  > limitations in the `pty` implementation. All `stderr` in `pty` mode
   243  > simply goes to `stdout`.
   244  
   245  ### Strings and Integers
   246  
   247  Options like `--name=""` expect a string, and they
   248  can only be specified once. Options like `-c=0`
   249  expect an integer, and they can only be specified once.