github.com/itscaro/cli@v0.0.0-20190705081621-c9db0fe93829/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/cli GitHub
     8       repository at https://github.com/docker/cli/. 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  # docker
    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    -c, --context string     Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with "docker context use")
    31    -D, --debug              Enable debug mode
    32        --help               Print usage
    33    -H, --host value         Daemon socket(s) to connect to (default [])
    34    -l, --log-level string   Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
    35        --tls                Use TLS; implied by --tlsverify
    36        --tlscacert string   Trust certs signed only by this CA (default "/root/.docker/ca.pem")
    37        --tlscert string     Path to TLS certificate file (default "/root/.docker/cert.pem")
    38        --tlskey string      Path to TLS key file (default "/root/.docker/key.pem")
    39        --tlsverify          Use TLS and verify the remote
    40    -v, --version            Print version information and quit
    41  
    42  Commands:
    43      attach    Attach to a running container
    44      # […]
    45  ```
    46  
    47  ## Description
    48  
    49  Depending on your Docker system configuration, you may be required to preface
    50  each `docker` command with `sudo`. To avoid having to use `sudo` with the
    51  `docker` command, your system administrator can create a Unix group called
    52  `docker` and add users to it.
    53  
    54  For more information about installing Docker or `sudo` configuration, refer to
    55  the [installation](https://docs.docker.com/install/) instructions for your operating system.
    56  
    57  ### Environment variables
    58  
    59  For easy reference, the following list of environment variables are supported
    60  by the `docker` command line:
    61  
    62  * `DOCKER_API_VERSION` The API version to use (e.g. `1.19`)
    63  * `DOCKER_CONFIG` The location of your client configuration files.
    64  * `DOCKER_CERT_PATH` The location of your authentication keys.
    65  * `DOCKER_CLI_EXPERIMENTAL` Enable experimental features for the cli (e.g. `enabled` or `disabled`)
    66  * `DOCKER_DRIVER` The graph driver to use.
    67  * `DOCKER_HOST` Daemon socket to connect to.
    68  * `DOCKER_NOWARN_KERNEL_VERSION` Prevent warnings that your Linux kernel is
    69    unsuitable for Docker.
    70  * `DOCKER_RAMDISK` If set this will disable 'pivot_root'.
    71  * `DOCKER_STACK_ORCHESTRATOR` Configure the default orchestrator to use when using `docker stack` management commands.
    72  * `DOCKER_TLS` When set Docker uses TLS.
    73  * `DOCKER_TLS_VERIFY` When set Docker uses TLS and verifies the remote.
    74  * `DOCKER_CONTENT_TRUST` When set Docker uses notary to sign and verify images.
    75    Equates to `--disable-content-trust=false` for build, create, pull, push, run.
    76  * `DOCKER_CONTENT_TRUST_SERVER` The URL of the Notary server to use. This defaults
    77    to the same URL as the registry.
    78  * `DOCKER_HIDE_LEGACY_COMMANDS` When set, Docker hides "legacy" top-level commands (such as `docker rm`, and
    79    `docker pull`) in `docker help` output, and only `Management commands` per object-type (e.g., `docker container`) are
    80    printed. This may become the default in a future release, at which point this environment-variable is removed.
    81  * `DOCKER_TMPDIR` Location for temporary Docker files.
    82  * `DOCKER_CONTEXT` Specify the context to use (overrides DOCKER_HOST env var and default context set with "docker context use")
    83  * `DOCKER_DEFAULT_PLATFORM` Specify the default platform for the commands that take the `--platform` flag.
    84  
    85  Because Docker is developed using Go, you can also use any environment
    86  variables used by the Go runtime. In particular, you may find these useful:
    87  
    88  * `HTTP_PROXY`
    89  * `HTTPS_PROXY`
    90  * `NO_PROXY`
    91  
    92  These Go environment variables are case-insensitive. See the
    93  [Go specification](http://golang.org/pkg/net/http/) for details on these
    94  variables.
    95  
    96  ### Configuration files
    97  
    98  By default, the Docker command line stores its configuration files in a
    99  directory called `.docker` within your `$HOME` directory. However, you can
   100  specify a different location via the `DOCKER_CONFIG` environment variable
   101  or the `--config` command line option. If both are specified, then the
   102  `--config` option overrides the `DOCKER_CONFIG` environment variable.
   103  For example:
   104  
   105      docker --config ~/testconfigs/ ps
   106  
   107  Instructs Docker to use the configuration files in your `~/testconfigs/`
   108  directory when running the `ps` command.
   109  
   110  Docker manages most of the files in the configuration directory
   111  and you should not modify them. However, you *can modify* the
   112  `config.json` file to control certain aspects of how the `docker`
   113  command behaves.
   114  
   115  Currently, you can modify the `docker` command behavior using environment
   116  variables or command-line options. You can also use options within
   117  `config.json` to modify some of the same behavior. When using these
   118  mechanisms, you must keep in mind the order of precedence among them. Command
   119  line options override environment variables and environment variables override
   120  properties you specify in a `config.json` file.
   121  
   122  The `config.json` file stores a JSON encoding of several properties:
   123  
   124  The property `HttpHeaders` specifies a set of headers to include in all messages
   125  sent from the Docker client to the daemon. Docker does not try to interpret or
   126  understand these header; it simply puts them into the messages. Docker does
   127  not allow these headers to change any headers it sets for itself.
   128  
   129  The property `psFormat` specifies the default format for `docker ps` output.
   130  When the `--format` flag is not provided with the `docker ps` command,
   131  Docker's client uses this property. If this property is not set, the client
   132  falls back to the default table format. For a list of supported formatting
   133  directives, see the
   134  [**Formatting** section in the `docker ps` documentation](ps.md)
   135  
   136  The property `imagesFormat` specifies the default format for `docker images` output.
   137  When the `--format` flag is not provided with the `docker images` command,
   138  Docker's client uses this property. If this property is not set, the client
   139  falls back to the default table format. For a list of supported formatting
   140  directives, see the [**Formatting** section in the `docker images` documentation](images.md)
   141  
   142  The property `pluginsFormat` specifies the default format for `docker plugin ls` output.
   143  When the `--format` flag is not provided with the `docker plugin ls` command,
   144  Docker's client uses this property. If this property is not set, the client
   145  falls back to the default table format. For a list of supported formatting
   146  directives, see the [**Formatting** section in the `docker plugin ls` documentation](plugin_ls.md)
   147  
   148  The property `servicesFormat` specifies the default format for `docker
   149  service ls` output. When the `--format` flag is not provided with the
   150  `docker service ls` command, Docker's client uses this property. If this
   151  property is not set, the client falls back to the default json format. For a
   152  list of supported formatting directives, see the
   153  [**Formatting** section in the `docker service ls` documentation](service_ls.md)
   154  
   155  The property `serviceInspectFormat` specifies the default format for `docker
   156  service inspect` output. When the `--format` flag is not provided with the
   157  `docker service inspect` command, Docker's client uses this property. If this
   158  property is not set, the client falls back to the default json format. For a
   159  list of supported formatting directives, see the
   160  [**Formatting** section in the `docker service inspect` documentation](service_inspect.md)
   161  
   162  The property `statsFormat` specifies the default format for `docker
   163  stats` output. When the `--format` flag is not provided with the
   164  `docker stats` command, Docker's client uses this property. If this
   165  property is not set, the client falls back to the default table
   166  format. For a list of supported formatting directives, see
   167  [**Formatting** section in the `docker stats` documentation](stats.md)
   168  
   169  The property `secretFormat` specifies the default format for `docker
   170  secret ls` output. When the `--format` flag is not provided with the
   171  `docker secret ls` command, Docker's client uses this property. If this
   172  property is not set, the client falls back to the default table
   173  format. For a list of supported formatting directives, see
   174  [**Formatting** section in the `docker secret ls` documentation](secret_ls.md)
   175  
   176  
   177  The property `nodesFormat` specifies the default format for `docker node ls` output.
   178  When the `--format` flag is not provided with the `docker node ls` command,
   179  Docker's client uses the value of `nodesFormat`. If the value of `nodesFormat` is not set,
   180  the client uses the default table format. For a list of supported formatting
   181  directives, see the [**Formatting** section in the `docker node ls` documentation](node_ls.md)
   182  
   183  The property `configFormat` specifies the default format for `docker
   184  config ls` output. When the `--format` flag is not provided with the
   185  `docker config ls` command, Docker's client uses this property. If this
   186  property is not set, the client falls back to the default table
   187  format. For a list of supported formatting directives, see
   188  [**Formatting** section in the `docker config ls` documentation](config_ls.md)
   189  
   190  The property `credsStore` specifies an external binary to serve as the default
   191  credential store. When this property is set, `docker login` will attempt to
   192  store credentials in the binary specified by `docker-credential-<value>` which
   193  is visible on `$PATH`. If this property is not set, credentials will be stored
   194  in the `auths` property of the config. For more information, see the
   195  [**Credentials store** section in the `docker login` documentation](login.md#credentials-store)
   196  
   197  The property `credHelpers` specifies a set of credential helpers to use
   198  preferentially over `credsStore` or `auths` when storing and retrieving
   199  credentials for specific registries. If this property is set, the binary
   200  `docker-credential-<value>` will be used when storing or retrieving credentials
   201  for a specific registry. For more information, see the
   202  [**Credential helpers** section in the `docker login` documentation](login.md#credential-helpers)
   203  
   204  The property `stackOrchestrator` specifies the default orchestrator to use when
   205  running `docker stack` management commands. Valid values are `"swarm"`,
   206  `"kubernetes"`, and `"all"`. This property can be overridden with the
   207  `DOCKER_STACK_ORCHESTRATOR` environment variable, or the `--orchestrator` flag.
   208  
   209  Once attached to a container, users detach from it and leave it running using
   210  the using `CTRL-p CTRL-q` key sequence. This detach key sequence is customizable
   211  using the `detachKeys` property. Specify a `<sequence>` value for the
   212  property. The format of the `<sequence>` is a comma-separated list of either
   213  a letter [a-Z], or the `ctrl-` combined with any of the following:
   214  
   215  * `a-z` (a single lowercase alpha character )
   216  * `@` (at sign)
   217  * `[` (left bracket)
   218  * `\\` (two backward slashes)
   219  *  `_` (underscore)
   220  * `^` (caret)
   221  
   222  Your customization applies to all containers started in with your Docker client.
   223  Users can override your custom or the default key sequence on a per-container
   224  basis. To do this, the user specifies the `--detach-keys` flag with the `docker
   225  attach`, `docker exec`, `docker run` or `docker start` command.
   226  
   227  The property `plugins` contains settings specific to CLI plugins. The
   228  key is the plugin name, while the value is a further map of options,
   229  which are specific to that plugin.
   230  
   231  Following is a sample `config.json` file:
   232  
   233  ```json
   234  {% raw %}
   235  {
   236    "HttpHeaders": {
   237      "MyHeader": "MyValue"
   238    },
   239    "psFormat": "table {{.ID}}\\t{{.Image}}\\t{{.Command}}\\t{{.Labels}}",
   240    "imagesFormat": "table {{.ID}}\\t{{.Repository}}\\t{{.Tag}}\\t{{.CreatedAt}}",
   241    "pluginsFormat": "table {{.ID}}\t{{.Name}}\t{{.Enabled}}",
   242    "statsFormat": "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}",
   243    "servicesFormat": "table {{.ID}}\t{{.Name}}\t{{.Mode}}",
   244    "secretFormat": "table {{.ID}}\t{{.Name}}\t{{.CreatedAt}}\t{{.UpdatedAt}}",
   245    "configFormat": "table {{.ID}}\t{{.Name}}\t{{.CreatedAt}}\t{{.UpdatedAt}}",
   246    "serviceInspectFormat": "pretty",
   247    "nodesFormat": "table {{.ID}}\t{{.Hostname}}\t{{.Availability}}",
   248    "detachKeys": "ctrl-e,e",
   249    "credsStore": "secretservice",
   250    "credHelpers": {
   251      "awesomereg.example.org": "hip-star",
   252      "unicorn.example.com": "vcbait"
   253    },
   254    "stackOrchestrator": "kubernetes",
   255    "plugins": {
   256      "plugin1": {
   257        "option": "value"
   258      },
   259      "plugin2": {
   260        "anotheroption": "anothervalue",
   261        "athirdoption": "athirdvalue"
   262      }
   263    }
   264  }
   265  {% endraw %}
   266  ```
   267  
   268  ### Notary
   269  
   270  If using your own notary server and a self-signed certificate or an internal
   271  Certificate Authority, you need to place the certificate at
   272  `tls/<registry_url>/ca.crt` in your docker config directory.
   273  
   274  Alternatively you can trust the certificate globally by adding it to your system's
   275  list of root Certificate Authorities.
   276  
   277  ## Examples
   278  
   279  ### Display help text
   280  
   281  To list the help on any command just execute the command, followed by the
   282  `--help` option.
   283  
   284      $ docker run --help
   285  
   286      Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
   287  
   288      Run a command in a new container
   289  
   290      Options:
   291            --add-host value             Add a custom host-to-IP mapping (host:ip) (default [])
   292        -a, --attach value               Attach to STDIN, STDOUT or STDERR (default [])
   293      ...
   294  
   295  ### Option types
   296  
   297  Single character command line options can be combined, so rather than
   298  typing `docker run -i -t --name test busybox sh`,
   299  you can write `docker run -it --name test busybox sh`.
   300  
   301  #### Boolean
   302  
   303  Boolean options take the form `-d=false`. The value you see in the help text is
   304  the default value which is set if you do **not** specify that flag. If you
   305  specify a Boolean flag without a value, this will set the flag to `true`,
   306  irrespective of the default value.
   307  
   308  For example, running `docker run -d` will set the value to `true`, so your
   309  container **will** run in "detached" mode, in the background.
   310  
   311  Options which default to `true` (e.g., `docker build --rm=true`) can only be
   312  set to the non-default value by explicitly setting them to `false`:
   313  
   314  ```bash
   315  $ docker build --rm=false .
   316  ```
   317  
   318  #### Multi
   319  
   320  You can specify options like `-a=[]` multiple times in a single command line,
   321  for example in these commands:
   322  
   323  ```bash
   324  $ docker run -a stdin -a stdout -i -t ubuntu /bin/bash
   325  
   326  $ docker run -a stdin -a stdout -a stderr ubuntu /bin/ls
   327  ```
   328  
   329  Sometimes, multiple options can call for a more complex value string as for
   330  `-v`:
   331  
   332  ```bash
   333  $ docker run -v /host:/container example/mysql
   334  ```
   335  
   336  > **Note**: Do not use the `-t` and `-a stderr` options together due to
   337  > limitations in the `pty` implementation. All `stderr` in `pty` mode
   338  > simply goes to `stdout`.
   339  
   340  #### Strings and Integers
   341  
   342  Options like `--name=""` expect a string, and they
   343  can only be specified once. Options like `-c=0`
   344  expect an integer, and they can only be specified once.