2016-10-14 18:30:36 -04:00
---
title: "Use the Docker command line"
description: "Docker's CLI command description and usage"
2016-11-03 18:48:30 -04:00
keywords: "Docker, Docker documentation, CLI, command line"
2019-12-06 04:46:54 -05:00
redirect_from:
2020-10-02 07:59:55 -04:00
- /go/experimental/
2019-12-06 04:46:54 -05:00
- /engine/reference/commandline/engine/
- /engine/reference/commandline/engine_activate/
- /engine/reference/commandline/engine_check/
- /engine/reference/commandline/engine_update/
2016-10-14 18:30:36 -04:00
---
2014-04-15 20:53:12 -04:00
2017-10-04 13:03:55 -04:00
<!-- This file is maintained within the docker/cli GitHub
2017-07-28 13:28:23 -04:00
repository at https://github.com/docker/cli/. Make all
2016-10-19 13:25:45 -04:00
pull requests against that repo. If you see this file in
another repository, consider it read-only there, as it will
periodically be overwritten by the definitive file. Pull
requests which include edits to this file in other repositories
will be rejected.
-->
2017-02-07 18:42:48 -05:00
# docker
2014-04-15 20:53:12 -04:00
2014-04-23 16:48:28 -04:00
To list available commands, either run `docker` with no parameters
or execute `docker help` :
2014-04-15 20:53:12 -04:00
2016-07-07 14:43:18 -04:00
```bash
$ docker
2016-11-04 22:45:15 -04:00
Usage: docker [OPTIONS] COMMAND [ARG...]
2016-07-07 14:43:18 -04:00
docker [ --help | -v | --version ]
A self-sufficient runtime for containers.
Options:
2016-09-25 10:26:46 -04:00
--config string Location of client config files (default "/root/.docker")
2018-11-09 09:10:41 -05:00
-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")
2016-09-25 10:26:46 -04:00
-D, --debug Enable debug mode
--help Print usage
-H, --host value Daemon socket(s) to connect to (default [])
2017-02-08 03:31:16 -05:00
-l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
2016-09-25 10:26:46 -04:00
--tls Use TLS; implied by --tlsverify
--tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem")
--tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem")
--tlskey string Path to TLS key file (default "/root/.docker/key.pem")
--tlsverify Use TLS and verify the remote
-v, --version Print version information and quit
2016-07-07 14:43:18 -04:00
Commands:
attach Attach to a running container
# […]
```
2015-05-27 13:38:29 -04:00
2017-02-07 18:42:48 -05:00
## Description
2015-05-27 13:38:29 -04:00
Depending on your Docker system configuration, you may be required to preface
each `docker` command with `sudo` . To avoid having to use `sudo` with the
`docker` command, your system administrator can create a Unix group called
2015-03-26 14:12:37 -04:00
`docker` and add users to it.
For more information about installing Docker or `sudo` configuration, refer to
Developer Certificate of Origin
Version 1.1
Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129
Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.
Developer's Certificate of Origin 1.1
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or
(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or
(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.
(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.
Signed-off-by: nkwangleiGIT <nkwanglei@126.com>
2018-05-16 08:16:08 -04:00
the [installation ](https://docs.docker.com/install/ ) instructions for your operating system.
2014-04-15 20:53:12 -04:00
2019-10-07 18:29:19 -04:00
## Environment variables
2015-03-24 13:08:37 -04:00
For easy reference, the following list of environment variables are supported
by the `docker` command line:
2015-08-31 17:45:27 -04:00
* `DOCKER_API_VERSION` The API version to use (e.g. `1.19` )
2015-04-28 11:00:18 -04:00
* `DOCKER_CONFIG` The location of your client configuration files.
2015-03-24 13:08:37 -04:00
* `DOCKER_HOST` Daemon socket to connect to.
2018-06-22 02:16:27 -04:00
* `DOCKER_STACK_ORCHESTRATOR` Configure the default orchestrator to use when using `docker stack` management commands.
2015-07-24 04:59:42 -04:00
* `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.
2015-10-26 19:54:47 -04:00
* `DOCKER_CONTENT_TRUST_SERVER` The URL of the Notary server to use. This defaults
to the same URL as the registry.
2017-02-07 18:42:48 -05:00
* `DOCKER_HIDE_LEGACY_COMMANDS` When set, Docker hides "legacy" top-level commands (such as `docker rm` , and
2016-12-31 08:17:34 -05:00
`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.
2018-11-09 09:10:41 -05:00
* `DOCKER_CONTEXT` Specify the context to use (overrides DOCKER_HOST env var and default context set with "docker context use")
2019-03-15 22:09:39 -04:00
* `DOCKER_DEFAULT_PLATFORM` Specify the default platform for the commands that take the `--platform` flag.
2015-03-24 13:08:37 -04:00
2018-01-12 12:30:31 -05:00
#### Shared Environment variables
These environment variables can be used both with the `docker` command line and
`dockerd` command line:
* `DOCKER_CERT_PATH` The location of your authentication keys.
* `DOCKER_TLS_VERIFY` When set Docker uses TLS and verifies the remote.
2016-11-24 15:07:06 -05:00
Because Docker is developed using Go, you can also use any environment
variables used by the Go runtime. In particular, you may find these useful:
2015-03-24 13:08:37 -04:00
* `HTTP_PROXY`
* `HTTPS_PROXY`
* `NO_PROXY`
These Go environment variables are case-insensitive. See the
[Go specification ](http://golang.org/pkg/net/http/ ) for details on these
variables.
2017-02-07 18:42:48 -05:00
### Configuration files
2015-04-01 18:39:37 -04:00
2015-04-28 11:00:18 -04:00
By default, the Docker command line stores its configuration files in a
2019-09-03 19:23:27 -04:00
directory called `.docker` within your `$HOME` directory.
2015-04-28 11:00:18 -04:00
Docker manages most of the files in the configuration directory
2019-10-07 18:29:19 -04:00
and you should not modify them. However, you *can* modify the
2015-04-28 11:00:18 -04:00
`config.json` file to control certain aspects of how the `docker`
2015-04-01 18:39:37 -04:00
command behaves.
2019-09-03 19:23:27 -04:00
You can modify the `docker` command behavior using environment
2015-05-27 13:38:29 -04:00
variables or command-line options. You can also use options within
2019-09-03 19:23:27 -04:00
`config.json` to modify some of the same behavior. If an environment variable
and the `--config` flag are set, the flag takes precedent over the environment
variable. Command line options override environment variables and environment
variables override properties you specify in a `config.json` file.
2019-10-07 18:29:19 -04:00
### Change the `.docker` directory
2019-09-03 19:23:27 -04:00
To specify a different directory, use the `DOCKER_CONFIG`
environment variable or the `--config` command line option. If both are
specified, then the `--config` option overrides the `DOCKER_CONFIG` environment
2019-10-07 18:29:19 -04:00
variable. The example below overrides the `docker ps` command using a
2019-09-03 19:23:27 -04:00
`config.json` file located in the `~/testconfigs/` directory.
```bash
$ docker --config ~/testconfigs/ ps
```
This flag only applies to whatever command is being ran. For persistent
configuration, you can set the `DOCKER_CONFIG` environment variable in your
shell (e.g. `~/.profile` or `~/.bashrc` ). The example below sets the new
directory to be `HOME/newdir/.docker` .
```bash
echo export DOCKER_CONFIG=$HOME/newdir/.docker > ~/.profile
```
2019-10-07 18:29:19 -04:00
### `config.json` properties
2015-04-01 18:39:37 -04:00
2015-07-17 00:03:16 -04:00
The `config.json` file stores a JSON encoding of several properties:
The property `HttpHeaders` specifies a set of headers to include in all messages
2015-05-27 13:38:29 -04:00
sent from the Docker client to the daemon. Docker does not try to interpret or
understand these header; it simply puts them into the messages. Docker does
not allow these headers to change any headers it sets for itself.
2015-04-01 18:39:37 -04:00
2015-07-17 00:03:16 -04:00
The property `psFormat` specifies the default format for `docker ps` output.
When the `--format` flag is not provided with the `docker ps` command,
Docker's client uses this property. If this property is not set, the client
falls back to the default table format. For a list of supported formatting
2016-01-03 17:03:39 -05:00
directives, see the
[**Formatting** section in the `docker ps` documentation ](ps.md )
2016-10-28 14:48:25 -04:00
The property `imagesFormat` specifies the default format for `docker images` output.
When the `--format` flag is not provided with the `docker images` command,
Docker's client uses this property. If this property is not set, the client
falls back to the default table format. For a list of supported formatting
directives, see the [**Formatting** section in the `docker images` documentation ](images.md )
2016-11-22 19:23:21 -05:00
The property `pluginsFormat` specifies the default format for `docker plugin ls` output.
When the `--format` flag is not provided with the `docker plugin ls` command,
Docker's client uses this property. If this property is not set, the client
falls back to the default table format. For a list of supported formatting
directives, see the [**Formatting** section in the `docker plugin ls` documentation ](plugin_ls.md )
2017-01-26 16:08:07 -05:00
The property `servicesFormat` specifies the default format for `docker
service ls` output. When the `--format` flag is not provided with the
`docker service ls` command, Docker's client uses this property. If this
property is not set, the client falls back to the default json format. For a
list of supported formatting directives, see the
[**Formatting** section in the `docker service ls` documentation ](service_ls.md )
2016-10-28 14:48:25 -04:00
The property `serviceInspectFormat` specifies the default format for `docker
service inspect` output. When the `--format` flag is not provided with the
`docker service inspect` command, Docker's client uses this property. If this
property is not set, the client falls back to the default json format. For a
list of supported formatting directives, see the
[**Formatting** section in the `docker service inspect` documentation ](service_inspect.md )
The property `statsFormat` specifies the default format for `docker
stats` output. When the `--format` flag is not provided with the
`docker stats` command, Docker's client uses this property. If this
property is not set, the client falls back to the default table
format. For a list of supported formatting directives, see
[**Formatting** section in the `docker stats` documentation ](stats.md )
2017-03-05 06:11:04 -05:00
The property `secretFormat` specifies the default format for `docker
secret ls` output. When the `--format` flag is not provided with the
`docker secret ls` command, Docker's client uses this property. If this
property is not set, the client falls back to the default table
format. For a list of supported formatting directives, see
[**Formatting** section in the `docker secret ls` documentation ](secret_ls.md )
2017-03-16 13:39:18 -04:00
2017-01-24 16:17:40 -05:00
The property `nodesFormat` specifies the default format for `docker node ls` output.
When the `--format` flag is not provided with the `docker node ls` command,
2017-03-08 13:29:15 -05:00
Docker's client uses the value of `nodesFormat` . If the value of `nodesFormat` is not set,
the client uses the default table format. For a list of supported formatting
2017-01-24 16:17:40 -05:00
directives, see the [**Formatting** section in the `docker node ls` documentation ](node_ls.md )
2017-03-05 06:11:04 -05:00
2017-03-16 13:39:18 -04:00
The property `configFormat` specifies the default format for `docker
config ls` output. When the `--format` flag is not provided with the
`docker config ls` command, Docker's client uses this property. If this
property is not set, the client falls back to the default table
format. For a list of supported formatting directives, see
[**Formatting** section in the `docker config ls` documentation ](config_ls.md )
2016-12-02 19:03:16 -05:00
The property `credsStore` specifies an external binary to serve as the default
credential store. When this property is set, `docker login` will attempt to
store credentials in the binary specified by `docker-credential-<value>` which
is visible on `$PATH` . If this property is not set, credentials will be stored
in the `auths` property of the config. For more information, see the
[**Credentials store** section in the `docker login` documentation ](login.md#credentials-store )
The property `credHelpers` specifies a set of credential helpers to use
preferentially over `credsStore` or `auths` when storing and retrieving
credentials for specific registries. If this property is set, the binary
`docker-credential-<value>` will be used when storing or retrieving credentials
for a specific registry. For more information, see the
[**Credential helpers** section in the `docker login` documentation ](login.md#credential-helpers )
2018-06-22 02:16:27 -04:00
The property `stackOrchestrator` specifies the default orchestrator to use when
running `docker stack` management commands. Valid values are `"swarm"` ,
`"kubernetes"` , and `"all"` . This property can be overridden with the
`DOCKER_STACK_ORCHESTRATOR` environment variable, or the `--orchestrator` flag.
2018-05-22 15:28:00 -04:00
The property `proxies` specifies proxy environment variables to be automatically
set on containers, and set as `--build-arg` on containers used during `docker build` .
A `"default"` set of proxies can be configured, and will be used for any docker
daemon that the client connects to, or a configuration per host (docker daemon),
for example, "https://docker-daemon1.example.com". The following properties can
be set for each environment:
* `httpProxy` (sets the value of `HTTP_PROXY` and `http_proxy` )
* `httpsProxy` (sets the value of `HTTPS_PROXY` and `https_proxy` )
* `ftpProxy` (sets the value of `FTP_PROXY` and `ftp_proxy` )
* `noProxy` (sets the value of `NO_PROXY` and `no_proxy` )
> **Warning**: Proxy settings may contain sensitive information (for example,
> if the proxy requires authentication). Environment variables are stored as
> plain text in the container's configuration, and as such can be inspected
> through the remote API or committed to an image when using `docker commit`.
2016-01-03 17:03:39 -05:00
Once attached to a container, users detach from it and leave it running using
the using `CTRL-p CTRL-q` key sequence. This detach key sequence is customizable
using the `detachKeys` property. Specify a `<sequence>` value for the
2016-10-14 18:30:36 -04:00
property. The format of the `<sequence>` is a comma-separated list of either
2016-01-14 16:58:41 -05:00
a letter [a-Z], or the `ctrl-` combined with any of the following:
2016-01-03 17:03:39 -05:00
* `a-z` (a single lowercase alpha character )
2016-02-05 16:47:57 -05:00
* `@` (at sign)
2016-01-03 17:03:39 -05:00
* `[` (left bracket)
* `\\` (two backward slashes)
* `_` (underscore)
* `^` (caret)
Your customization applies to all containers started in with your Docker client.
Users can override your custom or the default key sequence on a per-container
basis. To do this, the user specifies the `--detach-keys` flag with the `docker
attach`, `docker exec` , `docker run` or `docker start` command.
2015-07-17 00:03:16 -04:00
2019-02-18 09:23:30 -05:00
The property `plugins` contains settings specific to CLI plugins. The
key is the plugin name, while the value is a further map of options,
which are specific to that plugin.
2015-04-01 18:39:37 -04:00
Following is a sample `config.json` file:
2017-02-07 18:42:48 -05:00
```json
2017-06-26 15:50:34 -04:00
{% raw %}
2017-02-07 18:42:48 -05:00
{
"HttpHeaders": {
"MyHeader": "MyValue"
},
"psFormat": "table {{.ID}}\\t{{.Image}}\\t{{.Command}}\\t{{.Labels}}",
"imagesFormat": "table {{.ID}}\\t{{.Repository}}\\t{{.Tag}}\\t{{.CreatedAt}}",
"pluginsFormat": "table {{.ID}}\t{{.Name}}\t{{.Enabled}}",
"statsFormat": "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}",
"servicesFormat": "table {{.ID}}\t{{.Name}}\t{{.Mode}}",
2017-03-05 06:11:04 -05:00
"secretFormat": "table {{.ID}}\t{{.Name}}\t{{.CreatedAt}}\t{{.UpdatedAt}}",
2017-03-16 13:39:18 -04:00
"configFormat": "table {{.ID}}\t{{.Name}}\t{{.CreatedAt}}\t{{.UpdatedAt}}",
2017-02-07 18:42:48 -05:00
"serviceInspectFormat": "pretty",
2017-01-24 16:17:40 -05:00
"nodesFormat": "table {{.ID}}\t{{.Hostname}}\t{{.Availability}}",
2017-02-07 18:42:48 -05:00
"detachKeys": "ctrl-e,e",
"credsStore": "secretservice",
"credHelpers": {
"awesomereg.example.org": "hip-star",
"unicorn.example.com": "vcbait"
2018-06-22 02:16:27 -04:00
},
2019-02-18 09:23:30 -05:00
"stackOrchestrator": "kubernetes",
"plugins": {
"plugin1": {
"option": "value"
},
"plugin2": {
"anotheroption": "anothervalue",
"athirdoption": "athirdvalue"
}
2018-05-22 15:28:00 -04:00
},
"proxies": {
"default": {
"httpProxy": "http://user:pass@example.com:3128",
"httpsProxy": "http://user:pass@example.com:3128",
"noProxy": "http://user:pass@example.com:3128",
"ftpProxy": "http://user:pass@example.com:3128"
},
"https://manager1.mycorp.example.com:2377": {
"httpProxy": "http://user:pass@example.com:3128",
"httpsProxy": "http://user:pass@example.com:3128"
},
2019-02-18 09:23:30 -05:00
}
2017-02-07 18:42:48 -05:00
}
2017-06-26 15:50:34 -04:00
{% endraw %}
2017-02-07 18:42:48 -05:00
```
2015-04-01 18:39:37 -04:00
2019-09-03 19:23:27 -04:00
### Experimental features
2019-09-19 16:33:47 -04:00
Experimental features provide early access to future product functionality.
2020-10-02 08:19:34 -04:00
These features are intended for testing and feedback, and they may change
between releases without warning or can be removed from a future release.
2019-09-03 19:23:27 -04:00
2015-10-26 19:54:47 -04:00
### Notary
If using your own notary server and a self-signed certificate or an internal
Certificate Authority, you need to place the certificate at
`tls/<registry_url>/ca.crt` in your docker config directory.
Alternatively you can trust the certificate globally by adding it to your system's
list of root Certificate Authorities.
2017-02-07 18:42:48 -05:00
## Examples
### Display help text
2015-05-27 13:38:29 -04:00
To list the help on any command just execute the command, followed by the
`--help` option.
2014-10-15 17:14:12 -04:00
2015-03-26 14:12:37 -04:00
$ docker run --help
2014-10-15 17:14:12 -04:00
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Run a command in a new container
2016-09-12 04:08:59 -04:00
Options:
--add-host value Add a custom host-to-IP mapping (host:ip) (default [])
-a, --attach value Attach to STDIN, STDOUT or STDERR (default [])
2014-10-15 17:14:12 -04:00
...
2017-02-07 18:42:48 -05:00
### Option types
2014-04-15 20:53:12 -04:00
2015-02-03 22:36:52 -05:00
Single character command line options can be combined, so rather than
2015-02-27 09:45:37 -05:00
typing `docker run -i -t --name test busybox sh` ,
you can write `docker run -it --name test busybox sh` .
2014-04-15 20:53:12 -04:00
2017-02-07 18:42:48 -05:00
#### Boolean
2014-04-15 20:53:12 -04:00
2015-05-27 13:38:29 -04:00
Boolean options take the form `-d=false` . The value you see in the help text is
the default value which is set if you do **not** specify that flag. If you
specify a Boolean flag without a value, this will set the flag to `true` ,
irrespective of the default value.
2015-02-03 22:36:52 -05:00
2015-05-27 13:38:29 -04:00
For example, running `docker run -d` will set the value to `true` , so your
container **will** run in "detached" mode, in the background.
2015-02-03 22:36:52 -05:00
2015-05-27 13:38:29 -04:00
Options which default to `true` (e.g., `docker build --rm=true` ) can only be
set to the non-default value by explicitly setting them to `false` :
2015-02-03 22:36:52 -05:00
2017-02-07 18:42:48 -05:00
```bash
$ docker build --rm=false .
```
2014-04-15 20:53:12 -04:00
2017-02-07 18:42:48 -05:00
#### Multi
2014-04-15 20:53:12 -04:00
2015-04-07 16:25:48 -04:00
You can specify options like `-a=[]` multiple times in a single command line,
for example in these commands:
2014-04-15 20:53:12 -04:00
2017-02-07 18:42:48 -05:00
```bash
$ docker run -a stdin -a stdout -i -t ubuntu /bin/bash
$ docker run -a stdin -a stdout -a stderr ubuntu /bin/ls
```
2014-04-15 20:53:12 -04:00
2015-05-27 13:38:29 -04:00
Sometimes, multiple options can call for a more complex value string as for
`-v` :
2014-04-15 20:53:12 -04:00
2017-02-07 18:42:48 -05:00
```bash
$ docker run -v /host:/container example/mysql
```
2014-04-15 20:53:12 -04:00
2020-04-19 11:08:37 -04:00
> **Note**
>
> Do not use the `-t` and `-a stderr` options together due to
2015-05-27 13:38:29 -04:00
> limitations in the `pty` implementation. All `stderr` in `pty` mode
> simply goes to `stdout`.
2015-04-07 16:25:48 -04:00
2017-02-07 18:42:48 -05:00
#### Strings and Integers
2014-04-15 20:53:12 -04:00
Options like `--name=""` expect a string, and they
can only be specified once. Options like `-c=0`
expect an integer, and they can only be specified once.