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