Docker命令

帮助命令

docker version

显示Docker版本信息

  1. [root@localhost ~]# docker version
  2. Client: Docker Engine - Community
  3. Version: 19.03.13
  4. API version: 1.40
  5. Go version: go1.13.15
  6. Git commit: 4484c46d9d
  7. Built: Wed Sep 16 17:03:45 2020
  8. OS/Arch: linux/amd64
  9. Experimental: false
  10. Server: Docker Engine - Community
  11. Engine:
  12. Version: 19.03.13
  13. API version: 1.40 (minimum version 1.12)
  14. Go version: go1.13.15
  15. Git commit: 4484c46d9d
  16. Built: Wed Sep 16 17:02:21 2020
  17. OS/Arch: linux/amd64
  18. Experimental: false
  19. containerd:
  20. Version: 1.3.7
  21. GitCommit: 8fba4e9a7d01810a393d5d25a3621dc101981175
  22. runc:
  23. Version: 1.0.0-rc10
  24. GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
  25. docker-init:
  26. Version: 0.18.0
  27. GitCommit: fec3683
  28. [root@localhost ~]#

docker info

显示docker的系统信息,包括镜像和容器的数量。

  1. [root@localhost ~]# docker info
  2. Client:
  3. Debug Mode: false
  4. Server:
  5. Containers: 1
  6. Running: 0
  7. Paused: 0
  8. Stopped: 1
  9. Images: 1
  10. Server Version: 19.03.13
  11. Storage Driver: overlay2
  12. Backing Filesystem: xfs
  13. Supports d_type: true
  14. Native Overlay Diff: true
  15. Logging Driver: json-file
  16. Cgroup Driver: cgroupfs
  17. Plugins:
  18. Volume: local
  19. Network: bridge host ipvlan macvlan null overlay
  20. Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
  21. Swarm: inactive
  22. Runtimes: runc
  23. Default Runtime: runc
  24. Init Binary: docker-init
  25. containerd version: 8fba4e9a7d01810a393d5d25a3621dc101981175
  26. runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
  27. init version: fec3683
  28. Security Options:
  29. seccomp
  30. Profile: default
  31. Kernel Version: 3.10.0-1127.19.1.el7.x86_64
  32. Operating System: CentOS Linux 7 (Core)
  33. OSType: linux
  34. Architecture: x86_64
  35. CPUs: 1
  36. Total Memory: 1.777GiB
  37. Name: localhost.localdomain
  38. ID: 4ARA:NX4Y:7DM7:IGVR:XQNU:PNSQ:SDFN:44U2:VINY:2OMR:VDKO:2SKU
  39. Docker Root Dir: /var/lib/docker
  40. Debug Mode: false
  41. Registry: https://index.docker.io/v1/
  42. Labels:
  43. Experimental: false
  44. Insecure Registries:
  45. 127.0.0.0/8
  46. Registry Mirrors:
  47. https://gnxq79wc.mirror.aliyuncs.com/
  48. Live Restore Enabled: false
  49. [root@localhost ~]#

docker 命令 —help

帮助命令

https://docs.docker.com/
image.png
image.png

命令:https://docs.docker.com/engine/reference/commandline/

镜像命令

docker images

查看所有本地主机上的镜像
image.png

  1. [root@localhost ~]# docker images
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. hello-world latest bf756fb1ae65 10 months ago 13.3kB
  4. #解释
  5. REPOSITORY 镜像仓库源
  6. TAG 镜像的标签
  7. IMAGE ID 镜像的ID
  8. CREATED 镜像的创建时间
  9. SIZE 镜像的大小

Options选项

  1. [root@localhost ~]# docker images --help
  2. Usage: docker images [OPTIONS] [REPOSITORY[:TAG]]
  3. List images
  4. Options:
  5. -a, --all Show all images (default hides intermediate images)
  6. --digests Show digests #格式化
  7. -f, --filter filter Filter output based on conditions provided #过滤
  8. --format string Pretty-print images using a Go template
  9. --no-trunc Don't truncate output
  10. -q, --quiet Only show numeric IDs

解释

-a 列出所有镜像

-q 只显示镜像的ID

[root@localhost ~]# docker images -a
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              bf756fb1ae65        10 months ago       13.3kB
[root@localhost ~]# docker images -aq
bf756fb1ae65
[root@localhost ~]#

搜索命令

网页搜索

https://hub.docker.com/

image.png

docker search

docker search —help

[root@localhost ~]# docker search --help

Usage:    docker search [OPTIONS] TERM

Search the Docker Hub for images

Options:
  -f, --filter filter   Filter output based on conditions provided
      --format string   Pretty-print search using a Go template
      --limit int       Max number of search results (default 25)
      --no-trunc        Don't truncate output
[root@localhost ~]#

例如:

—filter=STARS=3000 #过滤出镜像收藏大于3000的

[root@localhost ~]# docker search mysql --filter=STARS=3000
NAME                DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
mysql               MySQL is a widely used, open-source relation…   10115               [OK]                
mariadb             MariaDB is a community-developed fork of MyS…   3715                [OK]                
[root@localhost ~]#

下载命令

docker pull

[root@localhost ~]# docker pull --help

Usage:    docker pull [OPTIONS] NAME[:TAG|@DIGEST]

Pull an image or a repository from a registry

Options:
  -a, --all-tags                Download all tagged images in the repository
      --disable-content-trust   Skip image verification (default true)
      --platform string         Set platform if server is multi-platform capable
  -q, --quiet                   Suppress verbose output
[root@localhost ~]#
[root@localhost ~]# docker pull mysql
Using default tag: latest   #如果不写tag:,默认下载最新的版本
latest: Pulling from library/mysql
bb79b6b2107f: Pull complete    #分层下载,docker image的核心:联合文件系统
49e22f6fb9f7: Pull complete 
842b1255668c: Pull complete 
9f48d1f43000: Pull complete 
c693f0615bce: Pull complete 
8a621b9dbed2: Pull complete 
0807d32aef13: Pull complete 
a56aca0feb17: Pull complete 
de9d45fd0f07: Pull complete 
1d68a49161cc: Pull complete 
d16d318b774e: Pull complete 
49e112c55976: Pull complete 
Digest: sha256:8c17271df53ee3b843d6e16d46cff13f22c9c04d6982eb15a9a47bd5c9ac7e2d   #签名
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest   #真实地址
[root@localhost ~]

docker pull mysql=docker pull docker.io/library/mysql:latest #等价

指定下载版本

docker pull 镜像名:tag

注:指定下载的版本必须是存在的。

联合文件系统,公用文件不在下载极大减少占用存储

比较:

[root@localhost ~]# docker pull mysql
Using default tag: latest
latest: Pulling from library/mysql
bb79b6b2107f: Pull complete 
49e22f6fb9f7: Pull complete 
842b1255668c: Pull complete 
9f48d1f43000: Pull complete 
c693f0615bce: Pull complete 
8a621b9dbed2: Pull complete 
0807d32aef13: Pull complete 
a56aca0feb17: Pull complete 
de9d45fd0f07: Pull complete 
1d68a49161cc: Pull complete 
d16d318b774e: Pull complete 
49e112c55976: Pull complete 
Digest: sha256:8c17271df53ee3b843d6e16d46cff13f22c9c04d6982eb15a9a47bd5c9ac7e2d
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest
[root@localhost ~]# docker pull mysql:5.7
5.7: Pulling from library/mysql
bb79b6b2107f: Already exists 
49e22f6fb9f7: Already exists 
842b1255668c: Already exists 
9f48d1f43000: Already exists 
c693f0615bce: Already exists 
8a621b9dbed2: Already exists 
0807d32aef13: Already exists 
f15d42f48bd9: Pull complete 
098ceecc0c8d: Pull complete 
b6fead9737bc: Pull complete 
351d223d3d76: Pull complete 
Digest: sha256:4d2b34e99c14edb99cdd95ddad4d9aa7ea3f2c4405ff0c3509a29dc40bcb10ef
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7
[root@localhost ~]#

查看下载的镜像

image.png

删除镜像命令

docker rmi -f id

docker rmi -f id1 id2 id3 #删除多个指定的容器镜像

通过ID删除镜像/通过TAG删除镜像
image.png
再次查看,mysql 5.7已被删除,只删除了部分层。
image.png

删除全部容器镜像

docker rmi -f $(docker images -aq)
image.png