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