Docker的镜像操作
从镜像仓库中拉取镜像时,需要国际联网访问DockerHub
1.镜像
镜像是一种轻量级,可执行的独立软件包,用来打包软件运行环境和基于运行环境开发的软件,它包含运行某个软件所需的所有内容,包括代码,运行时,库,环境变量和配置文件。
2.常见镜像操作
1.列出本地所有镜像
docker images
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
redis 7.0.11 4695a05c473a 16 months ago 130MB
nacos/nacos-server v2.2.3 17169ab516b8 17 months ago 814MB
sonatype/nexus3 3.54.1 9dcc5d2a8db6 18 months ago 550MB
mysql 8.0.31 c2c2eba5ae85 2 years ago 535MB
gitlab/gitlab-ce latest 46cd6954564a 2 years ago 2.36GB
adolfintel/speedtest latest 1bb6f28b9d23 2 years ago 439MB
prom/prometheus latest a3d385fc29f9 2 years ago 201MB
grafana/grafana latest 9b957e098315 2 years ago 275MB
portainer/portainer-ce latest 0df02179156a 2 years ago 273MB
mysql 5.7 db39680b63ac 4 years ago 437MB
kibana 7.4.2 230d3ded1abc 5 years ago 1.1GB
elasticsearch 7.4.2 b1179d41a7b4 5 years ago 855MB
各列含义
REPOSITORY
镜像的仓库源TAG
镜像的标签IMAGE ID
镜像的IDCREATED
镜像的创建时间SIZE
镜像大小
2.列出本地所有镜像(含中间镜像层)
docker images -a
[root@localhost ~]# docker images -a
REPOSITORY TAG IMAGE ID CREATED SIZE
redis 7.0.11 4695a05c473a 16 months ago 130MB
nacos/nacos-server v2.2.3 17169ab516b8 17 months ago 814MB
sonatype/nexus3 3.54.1 9dcc5d2a8db6 18 months ago 550MB
mysql 8.0.31 c2c2eba5ae85 2 years ago 535MB
gitlab/gitlab-ce latest 46cd6954564a 2 years ago 2.36GB
adolfintel/speedtest latest 1bb6f28b9d23 2 years ago 439MB
prom/prometheus latest a3d385fc29f9 2 years ago 201MB
grafana/grafana latest 9b957e098315 2 years ago 275MB
portainer/portainer-ce latest 0df02179156a 2 years ago 273MB
mysql 5.7 db39680b63ac 4 years ago 437MB
kibana 7.4.2 230d3ded1abc 5 years ago 1.1GB
elasticsearch 7.4.2 b1179d41a7b4 5 years ago 855MB
3.显示所有镜像ID
docker images -q
[root@localhost ~]# docker images -q
4695a05c473a
17169ab516b8
9dcc5d2a8db6
c2c2eba5ae85
46cd6954564a
1bb6f28b9d23
a3d385fc29f9
9b957e098315
0df02179156a
db39680b63ac
230d3ded1abc
b1179d41a7b4
4.摘要信息
docker images --digests
[root@localhost ~]# docker images --digests
REPOSITORY TAG DIGEST IMAGE ID CREATED SIZE
redis 7.0.11 sha256:1008c73f08e9f913868e2fa2e843212b62ea5bf3c66435d87bc7a6207bc0f1b4 4695a05c473a 16 months ago 130MB
nacos/nacos-server v2.2.3 sha256:cd7aa1cda9c639fbf6791d4bfea11a2596be18cc0d7f86f62ebd168076dd10c5 17169ab516b8 17 months ago 814MB
sonatype/nexus3 3.54.1 sha256:d1d3bd124102e98e2e2ab8aec865b7c5f2d34205e5487bac5e9cadb8b64363ae 9dcc5d2a8db6 18 months ago 550MB
mysql 8.0.31 sha256:d4055451e7f42869e64089a60d1abc9e66eccde2910629f0dd666b53a5f230d8 c2c2eba5ae85 2 years ago 535MB
gitlab/gitlab-ce latest sha256:5a0b03f09ab2f2634ecc6bfeb41521d19329cf4c9bbf330227117c048e7b5163 46cd6954564a 2 years ago 2.36GB
adolfintel/speedtest latest sha256:9716783d60e87a25e916869a73f0d2ccdc9d579e19820df6c98ef58052aca9c4 1bb6f28b9d23 2 years ago 439MB
prom/prometheus latest sha256:cb9817249c346d6cfadebe383ed3b3cd4c540f623db40c4ca00da2ada45259bb a3d385fc29f9 2 years ago 201MB
grafana/grafana latest sha256:18d94ae734accd66bccf22daed7bdb20c6b99aa0f2c687eea3ce4275fe275062 9b957e098315 2 years ago 275MB
portainer/portainer-ce latest sha256:4f126c5114b63e9d1bceb4b368944d14323329a9a0d4e7bb7eb53c9b7435d498 0df02179156a 2 years ago 273MB
mysql 5.7 sha256:b38555e593300df225daea22aeb104eed79fc80d2f064fde1e16e1804d00d0fc db39680b63ac 4 years ago 437MB
kibana 7.4.2 sha256:355f9c979dc9cdac3ff9a75a817b8b7660575e492bf7dbe796e705168f167efc 230d3ded1abc 5 years ago 1.1GB
elasticsearch 7.4.2 sha256:543bf7a3d61781bad337d31e6cc5895f16b55aed4da48f40c346352420927f74 b1179d41a7b4 5 years ago 855MB
5.不截取
docker images --no-trunc
[root@localhost ~]# docker images --no-trunc
REPOSITORY TAG IMAGE ID CREATED SIZE
redis 7.0.11 sha256:4695a05c473aa2db2dff0384abb06c2174832183ca0783d0a2720a922792add6 16 months ago 130MB
nacos/nacos-server v2.2.3 sha256:17169ab516b8dcbd1b79448471545063f827bca0cec8054101970d9d8e9cbb55 17 months ago 814MB
sonatype/nexus3 3.54.1 sha256:9dcc5d2a8db635dab8c98eec3bd1a10ae7deabfa0a6e73f51087ba09b0972961 18 months ago 550MB
mysql 8.0.31 sha256:c2c2eba5ae857a8ab9bffd11c5f15ed693dc65ac035948696f370f2895ae3062 2 years ago 535MB
gitlab/gitlab-ce latest sha256:46cd6954564a5a4ba6edd0cb19f6e0594d8a84c9d4a10a49f5f2caa485981fe8 2 years ago 2.36GB
adolfintel/speedtest latest sha256:1bb6f28b9d2386924b3d69790f59097680d0721afdb9b8f277201d314f8c583e 2 years ago 439MB
prom/prometheus latest sha256:a3d385fc29f926eed67f0d60ffaf72d199f3f9c24af5d55cd1802f2dc1dc9b4b 2 years ago 201MB
grafana/grafana latest sha256:9b957e098315598ae58c7a62bcc140ed086bbe619b38c31a52b21abbd5eb21e2 2 years ago 275MB
portainer/portainer-ce latest sha256:0df02179156afbf727443d0be50e8b9cdab8c044050691517539cea2e3ed01fd 2 years ago 273MB
mysql 5.7 sha256:db39680b63ac47a1d989da7b742f7b382af34d85a68214f8977bad59c05901a6 4 years ago 437MB
kibana 7.4.2 sha256:230d3ded1abc1468536e41d80a9cc6a67908358c0e4ebf065c29b8ef0370ba4b 5 years ago 1.1GB
elasticsearch 7.4.2 sha256:b1179d41a7b42f921f8ea0c5fa319c8aac4a3083dd733494170428917007e55f 5 years ago 855MB
6.搜索镜像
docker search jenkins
[root@localhost ~]# docker search jenkins
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
jenkins DEPRECATED; use "jenkins/jenkins:lts" instead 5696 [OK]
jenkins/jenkins The leading open source automation server 4049
jenkins/jnlp-slave a Jenkins agent which can connect to Jenkins… 157 [OK]
jenkins/inbound-agent This is an image for Jenkins agents using TC… 138
jenkins/agent This is a base image, which provides the Jen… 71
jenkins/ssh-agent Docker image for Jenkins agents connected ov… 60
jenkins/slave base image for a Jenkins Agent, which includ… 49 [OK]
jenkins/ssh-slave A Jenkins slave using SSH to establish conne… 41 [OK]
jenkins/jnlp-agent-maven A JNLP-based agent with Maven 3 built in 10
jenkins/jnlp-agent-docker 10
jenkins/evergreen An automatically self-updating Jenkins distr… 5
jenkins/pct Plugin Compat Tester - no longer published a… 5 [OK]
jenkins/jenkinsfile-runner Jenkinsfile Runner packages 3
jenkins/jnlp-agent-python A JNLP-based agent with Python built in 3
jenkins/jnlp-agent-python3 3
jenkins/jenkins-experimental Experimental images of Jenkins. These images… 3 [OK]
jenkins/jnlp-agent-coresdk 2
jenkins/jnlp-agent-alpine 2
jenkins/ath Jenkins Acceptance Test Harness 1 [OK]
jenkins/remoting-kafka-agent Remoting Kafka Agent 1 [OK]
jenkins/core-pr-tester Docker image for testing pull-requests sent … 1
jenkins/jnlp-agent-node 1
jenkins/jnlp-agent-ruby 1
jenkins/core-changelog-generator Tool for generating Jenkins core changelogs 1
jenkins/custom-war-packager Custom WAR Packager 1 [OK]
7.搜索star数目不少于多少的镜像
docker search --filter=stars=3 jenkins
[root@localhost ~]# docker search --filter=stars=3 jenkins
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
jenkins DEPRECATED; use "jenkins/jenkins:lts" instead 5696 [OK]
jenkins/jenkins The leading open source automation server 4049
jenkins/jnlp-slave a Jenkins agent which can connect to Jenkins… 157 [OK]
jenkins/inbound-agent This is an image for Jenkins agents using TC… 138
jenkins/agent This is a base image, which provides the Jen… 71
jenkins/ssh-agent Docker image for Jenkins agents connected ov… 60
jenkins/slave base image for a Jenkins Agent, which includ… 49 [OK]
jenkins/ssh-slave A Jenkins slave using SSH to establish conne… 41 [OK]
jenkins/jnlp-agent-maven A JNLP-based agent with Maven 3 built in 10
jenkins/jnlp-agent-docker 10
jenkins/pct Plugin Compat Tester - no longer published a… 5 [OK]
jenkins/evergreen An automatically self-updating Jenkins distr… 5
jenkins/jnlp-agent-python A JNLP-based agent with Python built in 3
jenkins/jenkins-experimental Experimental images of Jenkins. These images… 3 [OK]
jenkins/jenkinsfile-runner Jenkinsfile Runner packages 3
jenkins/jnlp-agent-python3 3
8.只列出自动构建类型的镜像
docker search --filter=is-automated=true jenkins
[root@localhost ~]# docker search --filter=is-automated=true jenkins
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
jenkins/jnlp-slave a Jenkins agent which can connect to Jenkins… 157 [OK]
jenkins/slave base image for a Jenkins Agent, which includ… 49 [OK]
jenkins/ssh-slave A Jenkins slave using SSH to establish conne… 41 [OK]
jenkins/pct Plugin Compat Tester - no longer published a… 5 [OK]
jenkins/jenkins-experimental Experimental images of Jenkins. These images… 3 [OK]
jenkins/ath Jenkins Acceptance Test Harness 1 [OK]
jenkins/remoting-kafka-agent Remoting Kafka Agent 1 [OK]
jenkins/custom-war-packager Custom WAR Packager 1 [OK]
9.拉取镜像
从远程仓库拉取一个镜像,版本号不写默认是last
docker pull 名称:版本
[root@localhost ~]# docker pull tomcat
Using default tag: latest
latest: Pulling from library/tomcat
afad30e59d72: Pull complete
918d361e6529: Pull complete
cf4dd2a7e40b: Pull complete
d152af7a0148: Pull complete
a5d7958ebd69: Pull complete
409b41a58ed4: Pull complete
4f4fb700ef54: Pull complete
9eabaa92f491: Pull complete
Digest: sha256:2ade2b0a424a446601688adc36c4dc568dfe5198f75c99c93352c412186ba3c9
Status: Downloaded newer image for tomcat:latest
10.删除镜像
删除镜像
版本号不写默认是last
docker rmi 名称:版本
[root@localhost ~]# docker rmi tomcat
Untagged: tomcat:latest
Untagged: tomcat@sha256:2ade2b0a424a446601688adc36c4dc568dfe5198f75c99c93352c412186ba3c9
Deleted: sha256:f77539e7e45f7c6337c681589fe18ee6407640e4066c450fcfb8c6a4ba5575b2
Deleted: sha256:ec216f70111f7e403bf2dd00786888a33e31e0b7d40b7a6963c413312b916a72
Deleted: sha256:0269bb8ab7750b1ccbbcee578df3af6edcba46c367891e319e3b874366c91b2e
Deleted: sha256:5ff949a6a98fa0b9294d5feab73bc2bd31947ecdf546d426d49401a5a5d8b9f4
Deleted: sha256:5e4268f1622d7392ab023aa0c458ee836bda8833e0b0f9d6b3333fff071bb761
Deleted: sha256:f9d1f11193bf543add78ce5660c14322fe3e03e957e07e2f6c4bbc3483fa2201
Deleted: sha256:5e2c15d15d3c100456584750cce4319bb58c9360f5dc2aa80a6ab92cf9910184
Deleted: sha256:ddf4cde2ad1fd66d3c8ea0d44fbd044cfa2928439880d5df6478af4f86e8efef
Deleted: sha256:958ed2862447477e5282173a7b21fbf9a5c83b8452b6e808f654fcea08613454
Deleted: sha256:27123a71e85e0540333291adccf7b9c340d089e8c3717c380d3b75cc8c7df90f
强制删除
docker rmi -f 镜像ID
删除全部
docker rmi -f $(docker images -qa)
删除多个
docker rmi -f 镜像名1:tag 镜像名2:tag
11.查看镜像/容器/数据卷所占空间
docker system df
[root@localhost ~]# docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 12 11 7.769GB 737.3MB (9%)
Containers 13 1 461MB 461MB (100%)
Local Volumes 9 5 710.5MB 501.2MB (70%)
Build Cache 0 0 0B 0B