背景说明
在 Docker 1.12 之前,大约有四十个左右的顶级命令,这些命令没有经过任何组织,显得十分混乱,对于新手来说,学习它们并不轻松。Docker 1.13 之后,将命令进行分组即Management Commands
相关问题
- 命令列表没有任何组织。对新手来说很难入门以及学习这些命令。(#8756)
- 有些命令,例如docker inspect也没有提供足够的上下文来说明他们是作用于镜像还是容器。这种镜像和容器的命令混合会带来困惑。(#13509)
- 缺乏命令名称的一致性。例如docker images是给所有镜像列表,而docker ps是给出容器列表。这些都有命名不一致的问题。(#8829)
有些命令像build和run被大量使用,还有那些神秘的像pause和wait命令却不经常使用。保持所有命令在同一个级别似乎不是很公平。
版本升级
1.13版本的主要特点:
使用Compose文件部署Swarm模式服务
- 改进命令行向后兼容
- 整理命令
- 命令行调整
- 改进Docker的监控与构建
命令分类
官方文档
https://docs.docker.com/engine/reference/commandline/cli/帮助命令
```bash [root@cka-master ~]# docker —help
Usage: docker [OPTIONS] COMMAND
A self-sufficient runtime for containers
Options: —config string Location of client config files (default “/root/.docker”) -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”) -D, —debug Enable debug mode -H, —host list Daemon socket(s) to connect to -l, —log-level string Set the logging level (“debug”|”info”|”warn”|”error”|”fatal”) (default “info”) —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
Management Commands: app Docker App (Docker Inc., v0.9.1-beta3) builder Manage builds buildx Docker Buildx (Docker Inc., v0.8.0-docker) config Manage Docker configs container Manage containers context Manage contexts image Manage images manifest Manage Docker image manifests and manifest lists network Manage networks node Manage Swarm nodes plugin Manage plugins scan* Docker Scan (Docker Inc., v0.17.0) secret Manage Docker secrets service Manage services stack Manage Docker stacks swarm Manage Swarm system Manage Docker trust Manage trust on Docker images volume Manage volumes
Commands: attach Attach local standard input, output, and error streams to a running container build Build an image from a Dockerfile commit Create a new image from a container’s changes cp Copy files/folders between a container and the local filesystem create Create a new container diff Inspect changes to files or directories on a container’s filesystem events Get real time events from the server exec Run a command in a running container export Export a container’s filesystem as a tar archive history Show the history of an image images List images import Import the contents from a tarball to create a filesystem image info Display system-wide information inspect Return low-level information on Docker objects kill Kill one or more running containers load Load an image from a tar archive or STDIN login Log in to a Docker registry logout Log out from a Docker registry logs Fetch the logs of a container pause Pause all processes within one or more containers port List port mappings or a specific mapping for the container ps List containers pull Pull an image or a repository from a registry push Push an image or a repository to a registry rename Rename a container restart Restart one or more containers rm Remove one or more containers rmi Remove one or more images run Run a command in a new container save Save one or more images to a tar archive (streamed to STDOUT by default) search Search the Docker Hub for images start Start one or more stopped containers stats Display a live stream of container(s) resource usage statistics stop Stop one or more running containers tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE top Display the running processes of a container unpause Unpause all processes within one or more containers update Update configuration of one or more containers version Show the Docker version information wait Block until one or more containers stop, then print their exit codes
Run ‘docker COMMAND —help’ for more information on a command.
To get more help with docker, check out our guides at https://docs.docker.com/go/guides/ [root@cka-master ~]#
<a name="hSonF"></a>### 顶级命令```bashCommands:attach Attach local standard input, output, and error streams to a running containerbuild Build an image from a Dockerfilecommit Create a new image from a container's changescp Copy files/folders between a container and the local filesystemcreate Create a new containerdiff Inspect changes to files or directories on a container's filesystemevents Get real time events from the serverexec Run a command in a running containerexport Export a container's filesystem as a tar archivehistory Show the history of an imageimages List imagesimport Import the contents from a tarball to create a filesystem imageinfo Display system-wide informationinspect Return low-level information on Docker objectskill Kill one or more running containersload Load an image from a tar archive or STDINlogin Log in to a Docker registrylogout Log out from a Docker registrylogs Fetch the logs of a containerpause Pause all processes within one or more containersport List port mappings or a specific mapping for the containerps List containerspull Pull an image or a repository from a registrypush Push an image or a repository to a registryrename Rename a containerrestart Restart one or more containersrm Remove one or more containersrmi Remove one or more imagesrun Run a command in a new containersave Save one or more images to a tar archive (streamed to STDOUT by default)search Search the Docker Hub for imagesstart Start one or more stopped containersstats Display a live stream of container(s) resource usage statisticsstop Stop one or more running containerstag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGEtop Display the running processes of a containerunpause Unpause all processes within one or more containersupdate Update configuration of one or more containersversion Show the Docker version informationwait Block until one or more containers stop, then print their exit codes
管理命令
Management Commands:app* Docker App (Docker Inc., v0.9.1-beta3)builder Manage buildsbuildx* Docker Buildx (Docker Inc., v0.8.0-docker)config Manage Docker configscontainer Manage containerscontext Manage contextsimage Manage imagesmanifest Manage Docker image manifests and manifest listsnetwork Manage networksnode Manage Swarm nodesplugin Manage pluginsscan* Docker Scan (Docker Inc., v0.17.0)secret Manage Docker secretsservice Manage servicesstack Manage Docker stacksswarm Manage Swarmsystem Manage Dockertrust Manage trust on Docker imagesvolume Manage volumes
可以通过设置环境变量DOCKER_HIDE_LEGACY_COMMANDS=true配置只显示管理命令
临时生效
[root@cka-master ~]# DOCKER_HIDE_LEGACY_COMMANDS=true docker --helpUsage: docker [OPTIONS] COMMANDA self-sufficient runtime for containersOptions:--config string Location of client config files (default "/root/.docker")-c, --context string Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with "dockercontext use")-D, --debug Enable debug mode-H, --host list Daemon socket(s) to connect to-l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")--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 quitManagement Commands:app* Docker App (Docker Inc., v0.9.1-beta3)builder Manage buildsbuildx* Docker Buildx (Docker Inc., v0.8.0-docker)config Manage Docker configscontainer Manage containerscontext Manage contextsimage Manage imagesmanifest Manage Docker image manifests and manifest listsnetwork Manage networksnode Manage Swarm nodesplugin Manage pluginsscan* Docker Scan (Docker Inc., v0.17.0)secret Manage Docker secretsservice Manage servicesstack Manage Docker stacksswarm Manage Swarmsystem Manage Dockertrust Manage trust on Docker imagesvolume Manage volumesCommands:build Build an image from a Dockerfilelogin Log in to a Docker registrylogout Log out from a Docker registryrun Run a command in a new containersearch Search the Docker Hub for imagesversion Show the Docker version informationRun 'docker COMMAND --help' for more information on a command.To get more help with docker, check out our guides at https://docs.docker.com/go/guides/[root@cka-master ~]#
会话生效
[root@cka-master ~]# export DOCKER_HIDE_LEGACY_COMMANDS=true[root@cka-master ~]# echo $DOCKER_HIDE_LEGACY_COMMANDStrue[root@cka-master ~]# docker --helpUsage: docker [OPTIONS] COMMANDA self-sufficient runtime for containersOptions:--config string Location of client config files (default "/root/.docker")-c, --context string Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with "dockercontext use")-D, --debug Enable debug mode-H, --host list Daemon socket(s) to connect to-l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")--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 quitManagement Commands:app* Docker App (Docker Inc., v0.9.1-beta3)builder Manage buildsbuildx* Docker Buildx (Docker Inc., v0.8.0-docker)config Manage Docker configscontainer Manage containerscontext Manage contextsimage Manage imagesmanifest Manage Docker image manifests and manifest listsnetwork Manage networksnode Manage Swarm nodesplugin Manage pluginsscan* Docker Scan (Docker Inc., v0.17.0)secret Manage Docker secretsservice Manage servicesstack Manage Docker stacksswarm Manage Swarmsystem Manage Dockertrust Manage trust on Docker imagesvolume Manage volumesCommands:build Build an image from a Dockerfilelogin Log in to a Docker registrylogout Log out from a Docker registryrun Run a command in a new containersearch Search the Docker Hub for imagesversion Show the Docker version informationRun 'docker COMMAND --help' for more information on a command.To get more help with docker, check out our guides at https://docs.docker.com/go/guides/[root@cka-master ~]#
永久生效
配置文件/etc/profile追加如下内容
export DOCKER_HIDE_LEGACY_COMMANDS=true
通过source /etc/profile命令生效
[root@cka-master ~]# docker --helpUsage: docker [OPTIONS] COMMANDA self-sufficient runtime for containersOptions:--config string Location of client config files (default "/root/.docker")-c, --context string Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with "dockercontext use")-D, --debug Enable debug mode-H, --host list Daemon socket(s) to connect to-l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")--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 quitManagement Commands:app* Docker App (Docker Inc., v0.9.1-beta3)builder Manage buildsbuildx* Docker Buildx (Docker Inc., v0.8.0-docker)config Manage Docker configscontainer Manage containerscontext Manage contextsimage Manage imagesmanifest Manage Docker image manifests and manifest listsnetwork Manage networksnode Manage Swarm nodesplugin Manage pluginsscan* Docker Scan (Docker Inc., v0.17.0)secret Manage Docker secretsservice Manage servicesstack Manage Docker stacksswarm Manage Swarmsystem Manage Dockertrust Manage trust on Docker imagesvolume Manage volumesCommands:build Build an image from a Dockerfilelogin Log in to a Docker registrylogout Log out from a Docker registryrun Run a command in a new containersearch Search the Docker Hub for imagesversion Show the Docker version informationRun 'docker COMMAND --help' for more information on a command.To get more help with docker, check out our guides at https://docs.docker.com/go/guides/[root@cka-master ~]#
