Docker学习之镜像管理(超详解析)

90 阅读4分钟

NAME DESCRIPTION STARS OFFICIAL AUTOMATED busybox Busybox base image. 3225 [OK]
radial/busyboxplus Full-chain, Internet enabled, busybox made f… 56 [OK] yauritux/busybox-curl Busybox with CURL 25
arm32v7/busybox Busybox base image. 10
arm64v8/busybox Busybox base image. 8
odise/busybox-curl 4 [OK] i386/busybox Busybox base image. 3
s390x/busybox Busybox base image. 3
prom/busybox Prometheus Busybox Docker base images 2 [OK] p7ppc64/busybox Busybox base image for ppc64. 2
hugegraph/busybox test image 2
joeshaw/busybox-nonroot Busybox container with non-root user nobody 2
busybox42/zimbra-docker-centos A Zimbra Docker image, based in ZCS 8.8.9 an… 2 [OK] openebs/busybox-client 1
amd64/busybox Busybox base image. 1
vukomir/busybox busybox and curl 1
ppc64le/busybox Busybox base image. 1
privatebin/chown Docker image providing busybox' chown, stat… 1
antrea/busybox 1
spotify/busybox Spotify fork of hub.docker.com/_/bus… 1
busybox42/nginx_php-docker-centos This is a nginx/php-fpm server running on Ce… 1 [OK] busybox42/haraka-docker-centos CentOS Haraka build with spamassassin, redis… 1 [OK] busybox42/alpine-pod 0
rancher/busybox 0
concourse/busyboxplus 0


#### 拉取镜像



[root@localhost ~]# docker pull busybox //拉取busybox(不指定版本时,默认拉取最近版本) Using default tag: latest latest: Pulling from library/busybox 5cc84ad355aa: Pull complete Digest: sha256:5acba83a746c7608ed544dc1533b87c737a0b0fb730301639a0179f9344b1678 Status: Downloaded newer image for busybox:latest [root@localhost ~]# docker pull ubuntu:18.04 //拉取ubuntu(也可以指定版本拉取) 18.04: Pulling from library/ubuntu 284055322776: Pull complete Digest: sha256:0fedbd5bd9fb72089c7bbca476949e10593cebed9b1fb9edf5b79dbbacddd7d6 Status: Downloaded newer image for ubuntu:18.04 [root@localhost ~]# docker pull registry.cn-hangzhou.aliyuncs.com/kongd/openlab:ubuntu_18.04 //由于docker拉取时是基于docker hub有时国内站点访问时可能会速度较慢,所以可以指定拉取国内阿里等站点的,也可以自己构建docker镜像站进行拉取。这里不做过多赘述。 ubuntu_18.04: Pulling from kongd/openlab Digest: sha256:fc0d6af5ab38dab33aa53643c4c4b312c6cd1f044c1a2229b2743b252b9689fc Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/kongd/openlab:ubuntu_18.04


#### 查看镜像信息



查看当前主机列表 [root@localhost ~]# docker images(也可以使用docker image ls命令来查看) REPOSITORY TAG IMAGE ID CREATED SIZE busybox latest beae173ccac6 2 years ago 1.24MB ubuntu 18.04 5a214d77f5d7 2 years ago 63.1MB registry.cn-hangzhou.aliyuncs.com/kongd/openlab ubuntu_18.04 5a214d77f5d7 2 years ago 63.1MB 查看镜像详细信息 [root@localhost ~]# docker inspect busybox //在此以查看busybox镜像信息为例 [ { "Id": "sha256:beae173ccac6ad749f76713cf4440fe3d21d1043fe616dfbe30775815d1d0f6a", "RepoTags": [ "busybox:latest" ], "RepoDigests": [ "busybox@sha256:5acba83a746c7608ed544dc1533b87c737a0b0fb730301639a0179f9344b1678" ], "Parent": "", "Comment": "", "Created": "2021-12-30T19:19:41.006954958Z", "Loaded": "2024-03-13T16:37:54.485607571+08:00", "Container": "a0007fa726185ffbcb68e90f8edabedd79a08949f32f4f0bcc6e5fed713a72c8", "ContainerConfig": { "Hostname": "a0007fa72618", "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 ["sh"]" ], "Image": "sha256:da658412c37aa24e561eb7e16c61bc82a9711340d8fb5cf1a8f39d8e96d7f723", "Volumes": null, "WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": {}, "Annotations": null }, "DockerVersion": "20.10.7", "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": [ "sh" ], "Image": "sha256:da658412c37aa24e561eb7e16c61bc82a9711340d8fb5cf1a8f39d8e96d7f723", "Volumes": null, "WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": null, "Annotations": null }, "Architecture": "amd64", "Os": "linux", "Size": 1239820, "VirtualSize": 1239820, "GraphDriver": { "Data": { "MergedDir": "/var/lib/docker/overlay2/4beb70f0835dd66d616bd0ae25176d019236743fd00eec1bda704ec6872297b3/merged", "UpperDir": "/var/lib/docker/overlay2/4beb70f0835dd66d616bd0ae25176d019236743fd00eec1bda704ec6872297b3/diff", "WorkDir": "/var/lib/docker/overlay2/4beb70f0835dd66d616bd0ae25176d019236743fd00eec1bda704ec6872297b3/work" }, "Name": "overlay2" }, "RootFS": { "Type": "layers", "Layers": [ "sha256:01fd6df81c8ec7dd24bbbd72342671f41813f992999a3471b9d9cbc44ad88374" ] }, "Metadata": { "LastTagTime": "0001-01-01T00:00:00Z" } } ]


#### 删除镜像



[root@localhost ~]# docker rmi ubuntu:18.04(也可用docker image rm ubuntu:18.04命令完成)如果删除时需要进行强制删除可以采用-f参数 Untagged: ubuntu:18.04 Untagged: ubuntu@sha256:0fedbd5bd9fb72089c7bbca476949e10593cebed9b1fb9edf5b79dbbacddd7d6 [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE busybox latest beae173ccac6 2 years ago 1.24MB myubuntu 18.04 5a214d77f5d7 2 years ago 63.1MB


#### 导出导入镜像