Movatterモバイル変換


[0]ホーム

URL:


Contact support
Contact support
Reference

docker

DescriptionThe base command for the Docker CLI.

Description

Depending on your Docker system configuration, you may be required to prefaceeachdocker command withsudo. To avoid having to usesudo with thedocker command, your system administrator can create a Unix group calleddocker and add users to it.

For more information about installing Docker orsudo configuration, refer totheinstallation instructions for your operating system.

Display help text

To list the help on any command just execute the command, followed by the--help option.

$ docker run --helpUsage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]Create and run a new container from an imageOptions:      --add-host value             Add a custom host-to-IP mapping (host:ip) (default [])  -a, --attach value               Attach to STDIN, STDOUT or STDERR (default [])<...>

Environment variables

The following list of environment variables are supported by thedocker commandline:

VariableDescription
DOCKER_API_VERSIONOverride the negotiated API version to use for debugging (e.g.1.19)
DOCKER_CERT_PATHLocation of your authentication keys. This variable is used both by thedocker CLI and thedockerd daemon
DOCKER_CONFIGThe location of your client configuration files.
DOCKER_CONTENT_TRUST_SERVERThe URL of the Notary server to use. Defaults to the same URL as the registry.
DOCKER_CONTENT_TRUSTWhen set Docker uses notary to sign and verify images. Equates to--disable-content-trust=false for build, create, pull, push, run.
DOCKER_CONTEXTName of thedocker context to use (overridesDOCKER_HOST env var and default context set withdocker context use)
DOCKER_CUSTOM_HEADERS(Experimental) Configurecustom HTTP headers to be sent by the client. Headers must be provided as a comma-separated list ofname=value pairs. This is the equivalent to theHttpHeaders field in the configuration file.
DOCKER_DEFAULT_PLATFORMDefault platform for commands that take the--platform flag.
DOCKER_HIDE_LEGACY_COMMANDSWhen set, Docker hides "legacy" top-level commands (such asdocker rm, anddocker pull) indocker help output, and onlyManagement commands per object-type (e.g.,docker container) are printed. This may become the default in a future release.
DOCKER_HOSTDaemon socket to connect to.
DOCKER_TLSEnable TLS for connections made by thedocker CLI (equivalent of the--tls command-line option). Set to a non-empty value to enable TLS. Note that TLS is enabled automatically if any of the other TLS options are set.
DOCKER_TLS_VERIFYWhen set Docker uses TLS and verifies the remote. This variable is used both by thedocker CLI and thedockerd daemon
BUILDKIT_PROGRESSSet type of progress output (auto,plain,tty,rawjson) whenbuilding withBuildKit backend. Use plain to show container output (defaultauto).

Because Docker is developed using Go, you can also use any environmentvariables used by the Go runtime. In particular, you may find these useful:

VariableDescription
HTTP_PROXYProxy URL for HTTP requests unless overridden by NoProxy.
HTTPS_PROXYProxy URL for HTTPS requests unless overridden by NoProxy.
NO_PROXYComma-separated values specifying hosts that should be excluded from proxying.

See theGo specificationfor details on these variables.

Option types

Single character command line options can be combined, so rather thantypingdocker run -i -t --name test busybox sh,you can writedocker run -it --name test busybox sh.

Boolean

Boolean options take the form-d=false. The value you see in the help text isthe default value which is set if you donot specify that flag. If youspecify a Boolean flag without a value, this will set the flag totrue,irrespective of the default value.

For example, runningdocker run -d will set the value totrue, so yourcontainerwill run in "detached" mode, in the background.

Options which default totrue (e.g.,docker build --rm=true) can only beset to the non-default value by explicitly setting them tofalse:

$ docker build --rm=false .

Multi

You can specify options like-a=[] multiple times in a single command line,for example in these commands:

$ docker run -a stdin -a stdout -i -t ubuntu /bin/bash$ docker run -a stdin -a stdout -a stderr ubuntu /bin/ls

Sometimes, multiple options can call for a more complex value string as for-v:

$ docker run -v /host:/container example/mysql
Note

Do not use the-t and-a stderr options together due tolimitations in thepty implementation. Allstderr inpty modesimply goes tostdout.

Strings and Integers

Options like--name="" expect a string, and theycan only be specified once. Options like-c=0expect an integer, and they can only be specified once.

Configuration files

By default, the Docker command line stores its configuration files in adirectory called.docker within your$HOME directory.

Docker manages most of the files in the configuration directoryand you shouldn't modify them. However, you can modify theconfig.json file to control certain aspects of how thedockercommand behaves.

You can modify thedocker command behavior using environmentvariables or command-line options. You can also use options withinconfig.json to modify some of the same behavior. If an environment variableand the--config flag are set, the flag takes precedent over the environmentvariable. Command line options override environment variables and environmentvariables override properties you specify in aconfig.json file.

Change the.docker directory

To specify a different directory, use theDOCKER_CONFIGenvironment variable or the--config command line option. If both arespecified, then the--config option overrides theDOCKER_CONFIG environmentvariable. The example below overrides thedocker ps command using aconfig.json file located in the~/testconfigs/ directory.

$ docker --config ~/testconfigs/ ps

This flag only applies to whatever command is being ran. For persistentconfiguration, you can set theDOCKER_CONFIG environment variable in yourshell (e.g.~/.profile or~/.bashrc). The example below sets the newdirectory to beHOME/newdir/.docker.

$echoexportDOCKER_CONFIG=$HOME/newdir/.docker > ~/.profile

Docker CLI configuration file (config.json) properties

Use the Docker CLI configuration to customize settings for thedocker CLI. Theconfiguration file uses JSON formatting, and properties:

By default, configuration file is stored in~/.docker/config.json. Refer to thechange the.docker directory section to use adifferent location.

Warning

The configuration file and other files inside the~/.docker configurationdirectory may contain sensitive information, such as authentication informationfor proxies or, depending on your credential store, credentials for your imageregistries. Review your configuration file's content before sharing with others,and prevent committing the file to version control.

Customize the default output format for commands

These fields lets you customize the default output format for some commandsif no--format flag is provided.

PropertyDescription
configFormatCustom default format fordocker config ls output. Seedocker config ls for a list of supported formatting directives.
imagesFormatCustom default format fordocker images /docker image ls output. Seedocker images for a list of supported formatting directives.
networksFormatCustom default format fordocker network ls output. Seedocker network ls for a list of supported formatting directives.
nodesFormatCustom default format fordocker node ls output. Seedocker node ls for a list of supported formatting directives.
pluginsFormatCustom default format fordocker plugin ls output. Seedocker plugin ls for a list of supported formatting directives.
psFormatCustom default format fordocker ps /docker container ps output. Seedocker ps for a list of supported formatting directives.
secretFormatCustom default format fordocker secret ls output. Seedocker secret ls for a list of supported formatting directives.
serviceInspectFormatCustom default format fordocker service inspect output. Seedocker service inspect for a list of supported formatting directives.
servicesFormatCustom default format fordocker service ls output. Seedocker service ls for a list of supported formatting directives.
statsFormatCustom default format fordocker stats output. Seedocker stats for a list of supported formatting directives.
tasksFormatCustom default format fordocker stack ps output. Seedocker stack ps for a list of supported formatting directives.
volumesFormatCustom default format fordocker volume ls output. Seedocker volume ls for a list of supported formatting directives.

Custom HTTP headers

The propertyHttpHeaders specifies a set of headers to include in all messagessent from the Docker client to the daemon. Docker doesn't try to interpret orunderstand these headers; it simply puts them into the messages. Docker doesnot allow these headers to change any headers it sets for itself.

Alternatively, use theDOCKER_CUSTOM_HEADERSenvironment variable,which is available in v27.1 and higher. This environment-variable is experimental,and its exact behavior may change.

Credential store options

The propertycredsStore specifies an external binary to serve as the defaultcredential store. When this property is set,docker login will attempt tostore credentials in the binary specified bydocker-credential-<value> whichis visible on$PATH. If this property isn't set, credentials are storedin theauths property of the CLI configuration file. For more information,see theCredential stores section in thedocker login documentation

The propertycredHelpers specifies a set of credential helpers to usepreferentially overcredsStore orauths when storing and retrievingcredentials for specific registries. If this property is set, the binarydocker-credential-<value> will be used when storing or retrieving credentialsfor a specific registry. For more information, see theCredential helpers section in thedocker login documentation

Automatic proxy configuration for containers

The propertyproxies specifies proxy environment variables to be automaticallyset on containers, and set as--build-arg on containers used duringdocker build.A"default" set of proxies can be configured, and will be used for any Dockerdaemon that the client connects to, or a configuration per host (Docker daemon),for example,https://docker-daemon1.example.com. The following properties canbe set for each environment:

PropertyDescription
httpProxyDefault value ofHTTP_PROXY andhttp_proxy for containers, and as--build-arg ondocker build
httpsProxyDefault value ofHTTPS_PROXY andhttps_proxy for containers, and as--build-arg ondocker build
ftpProxyDefault value ofFTP_PROXY andftp_proxy for containers, and as--build-arg ondocker build
noProxyDefault value ofNO_PROXY andno_proxy for containers, and as--build-arg ondocker build
allProxyDefault value ofALL_PROXY andall_proxy for containers, and as--build-arg ondocker build

These settings are used to configure proxy settings for containers only, and notused as proxy settings for thedocker CLI or thedockerd daemon. Refer to theenvironment variables andHTTP/HTTPS proxysections for configuring proxy settings for the CLI and daemon.

Warning

Proxy settings may contain sensitive information (for example, if the proxyrequires authentication). Environment variables are stored as plain text inthe container's configuration, and as such can be inspected through the remoteAPI or committed to an image when usingdocker commit.

Default key-sequence to detach from containers

Once attached to a container, users detach from it and leave it running usingthe usingCTRL-p CTRL-q key sequence. This detach key sequence is customizableusing thedetachKeys property. Specify a<sequence> value for theproperty. The format of the<sequence> is a comma-separated list of eithera letter [a-Z], or thectrl- combined with any of the following:

  • a-z (a single lowercase alpha character )
  • @ (at sign)
  • [ (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-containerbasis. To do this, the user specifies the--detach-keys flag with thedocker attach,docker exec,docker run ordocker start command.

CLI plugin options

The propertyplugins contains settings specific to CLI plugins. Thekey is the plugin name, while the value is a further map of options,which are specific to that plugin.

Sample configuration file

Following is a sampleconfig.json file to illustrate the format used forvarious fields:

{"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}}","secretFormat":"table {{.ID}}\t{{.Name}}\t{{.CreatedAt}}\t{{.UpdatedAt}}","configFormat":"table {{.ID}}\t{{.Name}}\t{{.CreatedAt}}\t{{.UpdatedAt}}","serviceInspectFormat":"pretty","nodesFormat":"table {{.ID}}\t{{.Hostname}}\t{{.Availability}}","detachKeys":"ctrl-e,e","credsStore":"secretservice","credHelpers":{"awesomereg.example.org":"hip-star","unicorn.example.com":"vcbait"},"plugins":{"plugin1":{"option":"value"},"plugin2":{"anotheroption":"anothervalue","athirdoption":"athirdvalue"}},"proxies":{"default":{"httpProxy":"http://user:pass@example.com:3128","httpsProxy":"https://my-proxy.example.com:3129","noProxy":"intra.mycorp.example.com","ftpProxy":"http://user:pass@example.com:3128","allProxy":"socks://example.com:1234"},"https://manager1.mycorp.example.com:2377":{"httpProxy":"http://user:pass@example.com:3128","httpsProxy":"https://my-proxy.example.com:3129"}}}

Experimental features

Experimental features provide early access to future product functionality.These features are intended for testing and feedback, and they may changebetween releases without warning or can be removed from a future release.

Starting with Docker 20.10, experimental CLI features are enabled by default,and require no configuration to enable them.

Notary

If using your own notary server and a self-signed certificate or an internalCertificate Authority, you need to place the certificate attls/<registry_url>/ca.crt in your Docker config directory.

Alternatively you can trust the certificate globally by adding it to your system'slist of root Certificate Authorities.

Options

OptionDefaultDescription
--config/root/.dockerLocation of client config files
-c, --contextName of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set withdocker context use)
-D, --debugEnable debug mode
-H, --hostDaemon socket to connect to
-l, --log-levelinfoSet the logging level (debug,info,warn,error,fatal)
--tlsUse TLS; implied by --tlsverify
--tlscacert/root/.docker/ca.pemTrust certs signed only by this CA
--tlscert/root/.docker/cert.pemPath to TLS certificate file
--tlskey/root/.docker/key.pemPath to TLS key file
--tlsverifyUse TLS and verify the remote

Examples

Specify daemon host (-H, --host)

You can use the-H,--host flag to specify a socket to use when you invokeadocker command. You can use the following protocols:

SchemeDescriptionExample
unix://[<path>]Unix socket (Linux only)unix:///var/run/docker.sock
tcp://[<IP or host>[:port]]TCP connectiontcp://174.17.0.1:2376
ssh://[username@]<IP or host>[:port]SSH connectionssh://user@192.168.64.5
npipe://[<name>]Named pipe (Windows only)npipe:////./pipe/docker_engine

If you don't specify the-H flag, and you're not using a customcontext,commands use the following default sockets:

  • unix:///var/run/docker.sock on macOS and Linux
  • npipe:////./pipe/docker_engine on Windows

To achieve a similar effect without having to specify the-H flag for everycommand, you could alsocreate a context,or alternatively, use theDOCKER_HOST environment variable.

For more information about the-H flag, seeDaemon socket option.

Using TCP sockets

The following example shows how to invokedocker ps over TCP, to a remotedaemon with IP address174.17.0.1, listening on port2376:

$ docker -H tcp://174.17.0.1:2376 ps
Note

By convention, the Docker daemon uses port2376 for secure TLS connections,and port2375 for insecure, non-TLS connections.

Using SSH sockets

When you use SSH invoke a command on a remote daemon, the request gets forwardedto the/var/run/docker.sock Unix socket on the SSH host.

$ docker -H ssh://user@192.168.64.5 ps

You can optionally specify the location of the socket by appending a pathcomponent to the end of the SSH address.

$ docker -H ssh://user@192.168.64.5/var/run/docker.sock ps

Subcommands

CommandDescription
docker build (legacy builder)Build an image from a Dockerfile
docker builderManage builds
docker buildxDocker Buildx
docker checkpointManage checkpoints
docker composeDocker Compose
docker configManage Swarm configs
docker containerManage containers
docker contextManage contexts
docker debugGet a shell into any container or image. An alternative to debugging with `docker exec`.
docker desktop (Beta)Docker Desktop
docker imageManage images
docker initCreates Docker-related starter files for your project
docker inspectReturn low-level information on Docker objects
docker loginAuthenticate to a registry
docker logoutLog out from a registry
docker manifestManage Docker image manifests and manifest lists
docker mcp
docker modelDocker Model Runner
docker networkManage networks
docker nodeManage Swarm nodes
docker offloadControl Docker Offload from the CLI
docker pluginManage plugins
docker scoutCommand line tool for Docker Scout
docker searchSearch Docker Hub for images
docker secretManage Swarm secrets
docker serviceManage Swarm services
docker stackManage Swarm stacks
docker swarmManage Swarm
docker systemManage Docker
docker trustManage trust on Docker images
docker versionShow the Docker version information
docker volumeManage volumes

[8]ページ先頭

©2009-2025 Movatter.jp