# Docker 镜像
# 1. 镜像拉取
docker pull 镜像名称:镜像版本
示例:
[root@VM-12-10-centos ~]# docker pull centos
Using default tag: latest
Trying to pull repository docker.io/library/centos ...
latest: Pulling from docker.io/library/centos
7a0437f04f83: Pull complete
Digest: sha256:5528e8b1b1719d34604c87e11dcd1c0a20bedf46e83b5632cdeac91b8c04efc1
Status: Downloaded newer image for docker.io/centos:latest
# 2. 查看镜像
docker images
示例:
[root@VM-12-10-centos ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
elasticsearch 7.12.1 41dc8ea0f139 2 months ago 851 MB
docker.io/centos latest 300e315adb2f 6 months ago 209 MB
# 3. 镜像搜索
docker search 镜像名
示例:
[root@VM-12-10-centos ~]# docker search nginx
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/nginx Official... 15034 [OK]
docker.io docker.io/jwilder/nginx-proxy Automated... 2038 [OK]
docker.io docker.io/richarvey/nginx-php-fpm Container... 814 [OK]
.....
.....
.....
# 4. 删除镜像
docker rmi 镜像名称或 ID
示例:
[root@VM-12-10-centos ~]# docker rmi docker.io/nginx
Untagged: docker.io/nginx:latest
Untagged: docker.io/nginx@sha256:6d75c99af15565a301e48297fa2d121e15d80ad526f8369c526324f0f7ccb750
Deleted: sha256:d1a364dc548d5357f0da3268c888e1971bbdb957ee3f028fe7194f1d61c6fdee
Deleted: sha256:fcc8faba78fe8a1f75025781c8fa1841079b75b54fce8408d039f73a48b7a81b
Deleted: sha256:a476b265974ace4c857e3d88b358e848f126297a8249840c72d5f5ea1954a4bf
Deleted: sha256:56722ee1ee7e73a5c6f96ea2959fa442fb4db9f044399bcd939bb0a6eb7919dc
Deleted: sha256:c657df997c75f6c1a9c5cc683e8e34c6f29e5b4c1dee60b632d3477fd5fdd644
Deleted: sha256:e9e1f772d2a8dbbeb6a4a4dcb4f0d07ff1c432bf94fac7a2db2216837bf9ec5b
Deleted: sha256:02c055ef67f5904019f43a41ea5f099996d8e7633749b6e606c400526b2c4b33
# 5. 查看镜像详细信息
docker inspect 镜像名称或 ID
示例:
[root@VM-12-10-centos ~]# docker inspect docker.io/centos
[
{
"Id": "sha256:300e315adb2f96afe5f0b2780b87f28ae95231fe3bdd1e16b9ba606307728f55",
"RepoTags": [
"docker.io/centos:latest"
],
"RepoDigests": [
"docker.io/centos@sha256:5528e8b1b1719d34604c87e11dcd1c0a20bedf46e83b5632cdeac91b8c04efc1"
],
"Parent": "",
"Comment": "",
"Created": "2020-12-08T00:22:53.076477777Z",
"Container": "395e0bfa7301f73bc994efe15099ea56b8836c608dd32614ac5ae279976d33e4",
"ContainerConfig": {
"Hostname": "395e0bfa7301",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/sh",
"-c",
"#(nop) ",
"CMD [\"/bin/bash\"]"
],
"Image": "sha256:6de05bdfbf9a9d403458d10de9e088b6d93d971dd5d48d18b4b6758f4554f451",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"org.label-schema.build-date": "20201204",
"org.label-schema.license": "GPLv2",
"org.label-schema.name": "CentOS Base Image",
"org.label-schema.schema-version": "1.0",
"org.label-schema.vendor": "CentOS"
}
},
"DockerVersion": "19.03.12",
"Author": "",
"Config": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/bash"
],
"Image": "sha256:6de05bdfbf9a9d403458d10de9e088b6d93d971dd5d48d18b4b6758f4554f451",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"org.label-schema.build-date": "20201204",
"org.label-schema.license": "GPLv2",
"org.label-schema.name": "CentOS Base Image",
"org.label-schema.schema-version": "1.0",
"org.label-schema.vendor": "CentOS"
}
},
"Architecture": "amd64",
"Os": "linux",
"Size": 209348104,
"VirtualSize": 209348104,
"GraphDriver": {
"Name": "overlay2",
"Data": {
"MergedDir": "/var/lib/docker/overlay2/300b2801244e5593bb0ab3091b0f897d4854890afe9664230dec50bd425e5bac/merged",
"UpperDir": "/var/lib/docker/overlay2/300b2801244e5593bb0ab3091b0f897d4854890afe9664230dec50bd425e5bac/diff",
"WorkDir": "/var/lib/docker/overlay2/300b2801244e5593bb0ab3091b0f897d4854890afe9664230dec50bd425e5bac/work"
}
},
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:2653d992f4ef2bfd27f94db643815aa567240c37732cae1405ad1c1309ee9859"
]
}
}
]
# 6. 保存镜像
保存镜像为压缩文件。
docker save -o 生成的压缩文件名 镜像名称或 ID
示例:
[root@VM-12-10-centos ~]# docker save -o centos.base.tar docker.io/centos
[root@VM-12-10-centos ~]# ll
-rw------- 1 root root 216535040 Jun 21 10:58 centos.base.tar
# 7. 载入镜像
从压缩文件载入镜像。
docker load -i 镜像压缩文件名称 镜像名称或 ID
示例:
[root@VM-12-10-centos ~]# docker load -i centos.base.tar
Loaded image: docker.io/centos:latest
# 8. 查看镜像大小
docker system df
示例:
[root@VM-12-10-centos ~]# docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 2 1 850.9 MB 209.3 MB (24%)
Containers 8 0 10.29 MB 10.29 MB (100%)
Local Volumes 0 0 0 B 0 B