1.帮助命令

docker verison 版本信息

docker info 具体内容的描述

docker —help 命令没有多少,不够再去看官方文档。

  1. Usage: docker [OPTIONS] COMMAND
  2. A self-sufficient runtime for containers
  3. Options:
  4. --config string Location of client config files (default "/root/.docker")
  5. -c, --context string Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set
  6. with "docker context use")
  7. -D, --debug Enable debug mode
  8. -H, --host list Daemon socket(s) to connect to
  9. -l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
  10. --tls Use TLS; implied by --tlsverify
  11. --tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem")
  12. --tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem")
  13. --tlskey string Path to TLS key file (default "/root/.docker/key.pem")
  14. --tlsverify Use TLS and verify the remote
  15. -v, --version Print version information and quit
  16. Management Commands:
  17. app* Docker App (Docker Inc., v0.9.1-beta3)
  18. builder Manage builds
  19. buildx* Build with BuildKit (Docker Inc., v0.5.1-docker)
  20. config Manage Docker configs
  21. container Manage containers
  22. context Manage contexts
  23. image Manage images
  24. manifest Manage Docker image manifests and manifest lists
  25. network Manage networks
  26. node Manage Swarm nodes
  27. plugin Manage plugins
  28. secret Manage Docker secrets
  29. service Manage services
  30. stack Manage Docker stacks
  31. swarm Manage Swarm
  32. system Manage Docker
  33. trust Manage trust on Docker images
  34. volume Manage volumes
  35. Commands:
  36. attach Attach local standard input, output, and error streams to a running container
  37. build Build an image from a Dockerfile
  38. commit Create a new image from a container's changes
  39. cp Copy files/folders between a container and the local filesystem
  40. create Create a new container
  41. diff Inspect changes to files or directories on a container's filesystem
  42. events Get real time events from the server
  43. exec Run a command in a running container
  44. export Export a container's filesystem as a tar archive
  45. history Show the history of an image
  46. images List images
  47. import Import the contents from a tarball to create a filesystem image
  48. info Display system-wide information
  49. inspect Return low-level information on Docker objects
  50. kill Kill one or more running containers
  51. load Load an image from a tar archive or STDIN
  52. login Log in to a Docker registry
  53. logout Log out from a Docker registry
  54. logs Fetch the logs of a container
  55. pause Pause all processes within one or more containers
  56. port List port mappings or a specific mapping for the container
  57. ps List containers
  58. pull Pull an image or a repository from a registry
  59. push Push an image or a repository to a registry
  60. rename Rename a container
  61. restart Restart one or more containers
  62. rm Remove one or more containers
  63. rmi Remove one or more images
  64. run Run a command in a new container
  65. save Save one or more images to a tar archive (streamed to STDOUT by default)
  66. search Search the Docker Hub for images
  67. start Start one or more stopped containers
  68. stats Display a live stream of container(s) resource usage statistics
  69. stop Stop one or more running containers
  70. tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
  71. top Display the running processes of a container
  72. unpause Unpause all processes within one or more containers
  73. update Update configuration of one or more containers
  74. version Show the Docker version information
  75. wait Block until one or more containers stop, then print their exit codes
  76. Run 'docker COMMAND --help' for more information on a command.
  77. To get more help with docker, check out our guides at https://docs.docker.com/go/guides/

2.镜像命令

docker images :列出主机上的镜像

  1. [root@test docker]# docker images
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. hello-world latest bf756fb1ae65 12 months ago 13.3kB

REPOSITORY:表示镜像的仓库源TAG:镜像的标签
IMAGE ID:镜像ID
CREATED:镜像创建时间
SIZE:镜像大小
同一仓库源可以有多个TAG,代表这个仓库源的不同个版本,我们使用REPOSITORY:TAG来定义不同的镜像。如果你不指定一个镜像的版本标签,例如你只使用ubuntu,docker将默认使用ubuntu:latest 镜像

docker images -a //列出本地所有的镜像

  1. [root@test docker]# docker images -a //列出本地所有的镜像
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. tomcat latest 040bdb29ab37 5 weeks ago 649MB
  4. hello-world latest bf756fb1ae65 13 months ago 13.3kB

docker images -q //只显示镜像ID

  1. [root@test docker]# docker images -q //只显示镜像ID
  2. 040bdb29ab37
  3. bf756fb1ae65

docker images -qa //显示所有镜像的ID

  1. [root@test docker]# docker images -qa //显示所有镜像的ID
  2. 040bdb29ab37
  3. bf756fb1ae65

docker images —digests //显示镜像的摘要信息

  1. [root@test docker]# docker images --digests //显示镜像的摘要信息
  2. REPOSITORY TAG DIGEST IMAGE ID CREATED SIZE
  3. hello-world latest sha256:1a523af650137b8accdaed439c17d684df61ee4d74feac151b5b337bd29e7eec bf756fb1ae65 12 months ago 13.3kB

docker images —no-trunc //显示完整的镜像信息

  1. [root@test docker]# docker images --no-trunc //显示完整的镜像信息
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. hello-world latest sha256:bf756fb1ae65adf866bd8c456593cd24beb6a0a061dedf42b26a993176745f6b 12 months ago 13.3kB

docker search tomcat 查找镜像

原理是从 hub.docker.com网站中搜的,但是是从阿里云下拉的。
OFFICIAL是官方版的,是自动构建的。

  1. [root@test docker]# docker search tomcat
  2. NAME DESCRIPTION STARS OFFICIAL AUTOMATED
  3. tomcat Apache Tomcat is an open source implementati 2916 [OK]
  4. tomee K]
  5. bitnami/tomcat Bitnami Tomcat Docker Image 37 [OK]
  6. kubeguide/tomcat-app Tomcat image for Chapter 1 29
  7. consol/tomcat-7.0 Tomcat 7.0.57, 8080, "admin/admin" 17 [OK]
  8. cloudesire/tomcat Tomcat server, 6/7/8 15 [OK]
  9. aallam/tomcat-mysql Debian, Oracle JDK, Tomcat & MySQL 13 [OK]
  10. arm32v7/tomcat Apache Tomcat is an open source implementati 10
  11. maluuba/tomcat7-java8 Tomcat7 with java8. 6
  12. rightctrl/tomcat CentOS , Oracle Java, tomcat application ssl 6 [OK]
  13. arm64v8/tomcat Apache Tomcat is an open source implementati 3
  14. cfje/tomcat-resource Tomcat Concourse Resource 2
  15. jelastic/tomcat An image of the Tomcat Java application serv 2
  16. amd64/tomcat Apache Tomcat is an open source implementati 2
  17. oobsri/tomcat8 Testing CI Jobs with different names. 1
  18. picoded/tomcat7 tomcat7 with jre8 and MANAGER_USER / MANAGER 1 [OK]
  19. chenyufeng/tomcat-centos tomcat基于centos6的镜像 1 [OK]
  20. camptocamp/tomcat-logback Docker image for tomcat with logback integra 1 [OK]
  21. 99taxis/tomcat7 Tomcat7 1 [OK]
  22. ppc64le/tomcat Apache Tomcat is an open source implementati 1
  23. appsvc/tomcat 1
  24. secoresearch/tomcat-varnish Tomcat and Varnish 5.0 0 [OK]
  25. s390x/tomcat Apache Tomcat is an open source implementati 0
  26. softwareplant/tomcat Tomcat images for jira-cloud testing 0 [OK]
  27. [root@test docker]#

docker pull tomcat 拉取镜像

docker pull tomcat 等于docker pull tomcat:latest 不加标签默认是下载了最新版

  1. Using default tag: latest
  2. latest: Pulling from library/tomcat
  3. 6c33745f49b4: Pull complete
  4. ef072fc32a84: Pull complete
  5. c0afb8e68e0b: Pull complete
  6. d599c07d28e6: Pull complete
  7. e8a829023b97: Pull complete //镜像是分层的
  8. d04be46a31d1: Pull complete
  9. db6007c69c35: Pull complete
  10. e4ad4c894bce: Pull complete
  11. 248895fda357: Pull complete
  12. 277059b4cba2: Pull complete
  13. Digest: sha256:57dae7dfb9b62a413cde65334c8a18893795cac70afc3be589c8336d8244655d
  14. Status: Downloaded newer image for tomcat:latest
  15. docker.io/library/tomcat:latest

docker rmi hello-world 删除单个镜像

  1. [root@test docker]# docker rmi hello-world
  2. Error response from daemon: conflict: unable to remove repository reference "hello-world" (must force) - container 04bb185c0723 is using its referenced image bf756fb1ae65
  3. //镜像正在运行,需要强制删除
  4. //需要强制删除的原因是有基于该镜像运行的容器,可能已经不运行,也有可能正在运行
  5. [root@test docker]# docker rmi -f hello-world
  6. Untagged: hello-world:latest
  7. Untagged: hello-world@sha256:1a523af650137b8accdaed439c17d684df61ee4d74feac151b5b337bd29e7eec
  8. Deleted: sha256:bf756fb1ae65adf866bd8c456593cd24beb6a0a061dedf42b26a993176745f6b
  9. //强制删除后:hello-world已经被删除。
  10. [root@test docker]# docker images
  11. REPOSITORY TAG IMAGE ID CREATED SIZE
  12. tomcat latest feba8d001e3f 3 weeks ago 649MB
  13. ------------------------------------------------------------------
  14. //找到基于该镜像产生的容器,删除容器再删除镜像就不会报错。
  15. /*
  16. 此时的容器已经结束运行,需要找个正在运行的容器,强制删除镜像后看容器还运不运行
  17. 经过 centos镜像的实验,强制删除镜像后,容器不会停止运行。
  18. 容器可以反复重启进入并输入命令进行操作。
  19. */
  20. [root@localhost loof]# docker ps -a
  21. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  22. b87506d81de2 hello-world "/hello" 24 minutes ago Exited (0) 24 minutes ago boring_boyd
  23. 742f05c65786 hello-world "/hello" 25 minutes ago Exited (0) 25 minutes ago silly_colden
  24. 5a9047fd260d hello-world "/hello" 25 minutes ago Exited (0) 25 minutes ago amazing_pascal
  25. //根据容器id删除过去产生的容器
  26. [root@localhost loof]# docker rm -f $(docker ps -qa)
  27. b87506d81de2
  28. 742f05c65786
  29. 5a9047fd260d
  30. [root@localhost loof]# docker images
  31. REPOSITORY TAG IMAGE ID CREATED SIZE
  32. tomcat latest 040bdb29ab37 5 weeks ago 649MB
  33. hello-world latest bf756fb1ae65 13 months ago 13.3kB
  34. //删除容器后删除镜像就不会报错
  35. [root@localhost loof]# docker rmi bf756fb1ae65
  36. Untagged: hello-world:latest
  37. Untagged: hello-world@sha256:31b9c7d48790f0d8c50ab433d9c3b7e17666d6993084c002c2ff1ca09b96391d
  38. Deleted: sha256:bf756fb1ae65adf866bd8c456593cd24beb6a0a061dedf42b26a993176745f6b
  39. Deleted: sha256:9c27e219663c25e0f28493790cc0b88bc973ba3b1686355f221c38a36978ac63

docker rmi hello-world tomcat 删除多个镜像

docker rmi -f $(docker images -qa) 根据镜像的id来删除