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