背景说明

在 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 ~]#

  1. <a name="hSonF"></a>
  2. ### 顶级命令
  3. ```bash
  4. Commands:
  5. attach Attach local standard input, output, and error streams to a running container
  6. build Build an image from a Dockerfile
  7. commit Create a new image from a container's changes
  8. cp Copy files/folders between a container and the local filesystem
  9. create Create a new container
  10. diff Inspect changes to files or directories on a container's filesystem
  11. events Get real time events from the server
  12. exec Run a command in a running container
  13. export Export a container's filesystem as a tar archive
  14. history Show the history of an image
  15. images List images
  16. import Import the contents from a tarball to create a filesystem image
  17. info Display system-wide information
  18. inspect Return low-level information on Docker objects
  19. kill Kill one or more running containers
  20. load Load an image from a tar archive or STDIN
  21. login Log in to a Docker registry
  22. logout Log out from a Docker registry
  23. logs Fetch the logs of a container
  24. pause Pause all processes within one or more containers
  25. port List port mappings or a specific mapping for the container
  26. ps List containers
  27. pull Pull an image or a repository from a registry
  28. push Push an image or a repository to a registry
  29. rename Rename a container
  30. restart Restart one or more containers
  31. rm Remove one or more containers
  32. rmi Remove one or more images
  33. run Run a command in a new container
  34. save Save one or more images to a tar archive (streamed to STDOUT by default)
  35. search Search the Docker Hub for images
  36. start Start one or more stopped containers
  37. stats Display a live stream of container(s) resource usage statistics
  38. stop Stop one or more running containers
  39. tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
  40. top Display the running processes of a container
  41. unpause Unpause all processes within one or more containers
  42. update Update configuration of one or more containers
  43. version Show the Docker version information
  44. wait Block until one or more containers stop, then print their exit codes

管理命令

  1. Management Commands:
  2. app* Docker App (Docker Inc., v0.9.1-beta3)
  3. builder Manage builds
  4. buildx* Docker Buildx (Docker Inc., v0.8.0-docker)
  5. config Manage Docker configs
  6. container Manage containers
  7. context Manage contexts
  8. image Manage images
  9. manifest Manage Docker image manifests and manifest lists
  10. network Manage networks
  11. node Manage Swarm nodes
  12. plugin Manage plugins
  13. scan* Docker Scan (Docker Inc., v0.17.0)
  14. secret Manage Docker secrets
  15. service Manage services
  16. stack Manage Docker stacks
  17. swarm Manage Swarm
  18. system Manage Docker
  19. trust Manage trust on Docker images
  20. volume Manage volumes

可以通过设置环境变量DOCKER_HIDE_LEGACY_COMMANDS=true配置只显示管理命令

临时生效

  1. [root@cka-master ~]# DOCKER_HIDE_LEGACY_COMMANDS=true docker --help
  2. Usage: docker [OPTIONS] COMMAND
  3. A self-sufficient runtime for containers
  4. Options:
  5. --config string Location of client config files (default "/root/.docker")
  6. -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
  7. context use")
  8. -D, --debug Enable debug mode
  9. -H, --host list Daemon socket(s) to connect to
  10. -l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
  11. --tls Use TLS; implied by --tlsverify
  12. --tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem")
  13. --tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem")
  14. --tlskey string Path to TLS key file (default "/root/.docker/key.pem")
  15. --tlsverify Use TLS and verify the remote
  16. -v, --version Print version information and quit
  17. Management Commands:
  18. app* Docker App (Docker Inc., v0.9.1-beta3)
  19. builder Manage builds
  20. buildx* Docker Buildx (Docker Inc., v0.8.0-docker)
  21. config Manage Docker configs
  22. container Manage containers
  23. context Manage contexts
  24. image Manage images
  25. manifest Manage Docker image manifests and manifest lists
  26. network Manage networks
  27. node Manage Swarm nodes
  28. plugin Manage plugins
  29. scan* Docker Scan (Docker Inc., v0.17.0)
  30. secret Manage Docker secrets
  31. service Manage services
  32. stack Manage Docker stacks
  33. swarm Manage Swarm
  34. system Manage Docker
  35. trust Manage trust on Docker images
  36. volume Manage volumes
  37. Commands:
  38. build Build an image from a Dockerfile
  39. login Log in to a Docker registry
  40. logout Log out from a Docker registry
  41. run Run a command in a new container
  42. search Search the Docker Hub for images
  43. version Show the Docker version information
  44. Run 'docker COMMAND --help' for more information on a command.
  45. To get more help with docker, check out our guides at https://docs.docker.com/go/guides/
  46. [root@cka-master ~]#

会话生效

  1. [root@cka-master ~]# export DOCKER_HIDE_LEGACY_COMMANDS=true
  2. [root@cka-master ~]# echo $DOCKER_HIDE_LEGACY_COMMANDS
  3. true
  4. [root@cka-master ~]# docker --help
  5. Usage: docker [OPTIONS] COMMAND
  6. A self-sufficient runtime for containers
  7. Options:
  8. --config string Location of client config files (default "/root/.docker")
  9. -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
  10. context use")
  11. -D, --debug Enable debug mode
  12. -H, --host list Daemon socket(s) to connect to
  13. -l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
  14. --tls Use TLS; implied by --tlsverify
  15. --tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem")
  16. --tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem")
  17. --tlskey string Path to TLS key file (default "/root/.docker/key.pem")
  18. --tlsverify Use TLS and verify the remote
  19. -v, --version Print version information and quit
  20. Management Commands:
  21. app* Docker App (Docker Inc., v0.9.1-beta3)
  22. builder Manage builds
  23. buildx* Docker Buildx (Docker Inc., v0.8.0-docker)
  24. config Manage Docker configs
  25. container Manage containers
  26. context Manage contexts
  27. image Manage images
  28. manifest Manage Docker image manifests and manifest lists
  29. network Manage networks
  30. node Manage Swarm nodes
  31. plugin Manage plugins
  32. scan* Docker Scan (Docker Inc., v0.17.0)
  33. secret Manage Docker secrets
  34. service Manage services
  35. stack Manage Docker stacks
  36. swarm Manage Swarm
  37. system Manage Docker
  38. trust Manage trust on Docker images
  39. volume Manage volumes
  40. Commands:
  41. build Build an image from a Dockerfile
  42. login Log in to a Docker registry
  43. logout Log out from a Docker registry
  44. run Run a command in a new container
  45. search Search the Docker Hub for images
  46. version Show the Docker version information
  47. Run 'docker COMMAND --help' for more information on a command.
  48. To get more help with docker, check out our guides at https://docs.docker.com/go/guides/
  49. [root@cka-master ~]#

永久生效

配置文件/etc/profile追加如下内容

  1. export DOCKER_HIDE_LEGACY_COMMANDS=true

通过source /etc/profile命令生效

  1. [root@cka-master ~]# docker --help
  2. Usage: docker [OPTIONS] COMMAND
  3. A self-sufficient runtime for containers
  4. Options:
  5. --config string Location of client config files (default "/root/.docker")
  6. -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
  7. context use")
  8. -D, --debug Enable debug mode
  9. -H, --host list Daemon socket(s) to connect to
  10. -l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
  11. --tls Use TLS; implied by --tlsverify
  12. --tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem")
  13. --tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem")
  14. --tlskey string Path to TLS key file (default "/root/.docker/key.pem")
  15. --tlsverify Use TLS and verify the remote
  16. -v, --version Print version information and quit
  17. Management Commands:
  18. app* Docker App (Docker Inc., v0.9.1-beta3)
  19. builder Manage builds
  20. buildx* Docker Buildx (Docker Inc., v0.8.0-docker)
  21. config Manage Docker configs
  22. container Manage containers
  23. context Manage contexts
  24. image Manage images
  25. manifest Manage Docker image manifests and manifest lists
  26. network Manage networks
  27. node Manage Swarm nodes
  28. plugin Manage plugins
  29. scan* Docker Scan (Docker Inc., v0.17.0)
  30. secret Manage Docker secrets
  31. service Manage services
  32. stack Manage Docker stacks
  33. swarm Manage Swarm
  34. system Manage Docker
  35. trust Manage trust on Docker images
  36. volume Manage volumes
  37. Commands:
  38. build Build an image from a Dockerfile
  39. login Log in to a Docker registry
  40. logout Log out from a Docker registry
  41. run Run a command in a new container
  42. search Search the Docker Hub for images
  43. version Show the Docker version information
  44. Run 'docker COMMAND --help' for more information on a command.
  45. To get more help with docker, check out our guides at https://docs.docker.com/go/guides/
  46. [root@cka-master ~]#