2015-06-07 23:07:20 -04:00
|
|
|
<!--[metadata]>
|
|
|
|
+++
|
2015-10-08 10:20:06 -04:00
|
|
|
title = "Use the Docker command line"
|
2015-06-07 23:07:20 -04:00
|
|
|
description = "Docker's CLI command description and usage"
|
|
|
|
keywords = ["Docker, Docker documentation, CLI, command line"]
|
|
|
|
[menu.main]
|
2015-06-21 16:41:38 -04:00
|
|
|
parent = "smn_cli"
|
2015-10-08 10:20:06 -04:00
|
|
|
weight = -2
|
2015-06-07 23:07:20 -04:00
|
|
|
+++
|
|
|
|
<![end-metadata]-->
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2015-10-08 10:20:06 -04:00
|
|
|
# Use the Docker command line
|
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
|
|
|
|
Usage: docker [OPTIONS] COMMAND [arg...]
|
|
|
|
docker [ --help | -v | --version ]
|
|
|
|
|
|
|
|
A self-sufficient runtime for containers.
|
|
|
|
|
|
|
|
Options:
|
|
|
|
|
|
|
|
--config=~/.docker Location of client config files
|
|
|
|
-D, --debug Enable debug mode
|
|
|
|
-H, --host=[] Daemon socket(s) to connect to
|
|
|
|
-h, --help Print usage
|
|
|
|
-l, --log-level=info Set the logging level
|
|
|
|
--tls Use TLS; implied by --tlsverify
|
|
|
|
--tlscacert=~/.docker/ca.pem Trust certs signed only by this CA
|
|
|
|
--tlscert=~/.docker/cert.pem Path to TLS certificate file
|
|
|
|
--tlskey=~/.docker/key.pem Path to TLS key file
|
|
|
|
--tlsverify Use TLS and verify the remote
|
|
|
|
-v, --version Print version information and quit
|
|
|
|
|
|
|
|
Commands:
|
|
|
|
attach Attach to a running container
|
|
|
|
# […]
|
|
|
|
```
|
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
|
2015-11-22 20:15:39 -05:00
|
|
|
the [installation](../../installation/index.md) instructions for your operating system.
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2015-04-21 11:50:09 -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_CERT_PATH` The location of your authentication keys.
|
|
|
|
* `DOCKER_DRIVER` The graph driver to use.
|
|
|
|
* `DOCKER_HOST` Daemon socket to connect to.
|
2015-05-27 13:38:29 -04:00
|
|
|
* `DOCKER_NOWARN_KERNEL_VERSION` Prevent warnings that your Linux kernel is
|
|
|
|
unsuitable for Docker.
|
2015-03-24 13:08:37 -04:00
|
|
|
* `DOCKER_RAMDISK` If set this will disable 'pivot_root'.
|
|
|
|
* `DOCKER_TLS_VERIFY` When set Docker uses TLS and verifies the remote.
|
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.
|
2015-03-24 13:08:37 -04:00
|
|
|
* `DOCKER_TMPDIR` Location for temporary Docker files.
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
* `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.
|
|
|
|
|
2015-04-21 11:50:09 -04: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
|
2016-03-12 08:11:01 -05:00
|
|
|
directory called `.docker` within your `$HOME` directory. However, you can
|
2015-04-28 11:00:18 -04:00
|
|
|
specify a different location via the `DOCKER_CONFIG` environment variable
|
|
|
|
or the `--config` command line option. If both are specified, then the
|
|
|
|
`--config` option overrides the `DOCKER_CONFIG` environment variable.
|
|
|
|
For example:
|
|
|
|
|
|
|
|
docker --config ~/testconfigs/ ps
|
|
|
|
|
|
|
|
Instructs Docker to use the configuration files in your `~/testconfigs/`
|
|
|
|
directory when running the `ps` command.
|
|
|
|
|
|
|
|
Docker manages most of the files in the configuration directory
|
|
|
|
and you should not modify them. However, you *can modify* the
|
|
|
|
`config.json` file to control certain aspects of how the `docker`
|
2015-04-01 18:39:37 -04:00
|
|
|
command behaves.
|
|
|
|
|
2015-05-27 13:38:29 -04:00
|
|
|
Currently, you can modify the `docker` command behavior using environment
|
|
|
|
variables or command-line options. You can also use options within
|
|
|
|
`config.json` to modify some of the same behavior. When using these
|
|
|
|
mechanisms, you must keep in mind the order of precedence among them. Command
|
|
|
|
line options override environment variables and environment variables override
|
2015-04-01 18:39:37 -04:00
|
|
|
properties you specify in a `config.json` file.
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
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-01-14 16:58:41 -05:00
|
|
|
property. The format of the `<sequence>` is a comma-separated list of either
|
|
|
|
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
|
|
|
|
2015-12-18 08:03:41 -05: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)
|
|
|
|
|
2015-04-01 18:39:37 -04:00
|
|
|
Following is a sample `config.json` file:
|
|
|
|
|
|
|
|
{
|
2015-07-26 05:57:45 -04:00
|
|
|
"HttpHeaders": {
|
2015-04-01 18:39:37 -04:00
|
|
|
"MyHeader": "MyValue"
|
2015-07-17 00:03:16 -04:00
|
|
|
},
|
2016-01-03 17:03:39 -05:00
|
|
|
"psFormat": "table {{.ID}}\\t{{.Image}}\\t{{.Command}}\\t{{.Labels}}",
|
|
|
|
"imagesFormat": "table {{.ID}}\\t{{.Repository}}\\t{{.Tag}}\\t{{.CreatedAt}}",
|
|
|
|
"detachKeys": "ctrl-e,e"
|
2015-04-01 18:39:37 -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.
|
|
|
|
|
2014-10-15 17:14:12 -04:00
|
|
|
## Help
|
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
|
|
|
|
|
2015-03-03 12:04:06 -05:00
|
|
|
-a, --attach=[] Attach to STDIN, STDOUT or STDERR
|
2015-10-16 15:05:18 -04:00
|
|
|
--cpu-shares=0 CPU shares (relative weight)
|
2014-10-15 17:14:12 -04:00
|
|
|
...
|
|
|
|
|
2014-04-15 20:53:12 -04:00
|
|
|
## Option types
|
|
|
|
|
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
|
|
|
|
|
|
|
### Boolean
|
|
|
|
|
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
|
|
|
|
|
|
|
$ docker build --rm=false .
|
2014-04-15 20:53:12 -04:00
|
|
|
|
|
|
|
### Multi
|
|
|
|
|
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
|
|
|
|
2015-04-07 16:25:48 -04:00
|
|
|
$ 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
|
|
|
|
2015-03-26 14:12:37 -04:00
|
|
|
$ docker run -v /host:/container example/mysql
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2015-05-27 13:38:29 -04:00
|
|
|
> **Note:**
|
|
|
|
> Do not use the `-t` and `-a stderr` options together due to
|
|
|
|
> limitations in the `pty` implementation. All `stderr` in `pty` mode
|
|
|
|
> simply goes to `stdout`.
|
2015-04-07 16:25:48 -04:00
|
|
|
|
2014-04-15 20:53:12 -04:00
|
|
|
### Strings and Integers
|
|
|
|
|
|
|
|
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.
|