Docker镜像管理

Posted 青衫解衣

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Docker镜像管理相关的知识,希望对你有一定的参考价值。

获取docker busybox镜像

[root@harbor <sub>]# docker pull busybox
Using default tag: latest
latest: Pulling from library/busybox
5cc84ad355aa: Pull complete
Digest: sha256:5acba83a746c7608ed544dc1533b87c737a0b0fb730301639a0179f9344b1678
Status: Downloaded newer image for busybox:latest
docker.io/library/busybox:latest
[root@harbor </sub>]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest beae173ccac6 3 months ago 1.24MB
nginx latest 605c77e624dd 3 months ago 141MB

显示完整的docker镜像ID,--no-trunc参数

[root@harbor ~]# docker images --no-trunc

Docker镜像管理_Docker镜像管理

查看当前docker镜像

[root@harbor ~]# docker images 
REPOSITORY TAG IMAGE ID CREATED SIZE
redis v1 07d6e5a00daa 2 weeks ago 109MB
nginx latest 605c77e624dd 3 months ago 141MB
redis latest 7614ae9453d1 3 months ago 113MB
centos 7 eeb6ee3f44bd 7 months ago 204MB
centos latest 5d0da3dc9764 7 months ago 231MB

docker镜像打tag

[root@harbor ~]# docker tag nginx:latest nginx:v1

Docker镜像管理_Docker镜像管理_02

批量删除docker images

第一种方法:

[root@harbor <sub>]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latet 605c77e624dd 3 months ago 141MB
redis latest 7614ae9453d1 3 months ago 113MB
centos 7 eeb6ee3f44bd 6 months ago 204MB

[root@harbor </sub>]# docker images -q
605c77e624dd
7614ae9453d1
eeb6ee3f44bd

[root@harbor ~]# docker rmi $(docker images -q)
Untagged: nginx:latest
Untagged: nginx@sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31
Deleted: sha256:605c77e624ddb75e6110f997c58876baa13f8754486b461117934b24a9dc3a85
Deleted: sha256:b625d8e29573fa369e799ca7c5df8b7a902126d2b7cbeb390af59e4b9e1210c5
Deleted: sha256:7850d382fb05e393e211067c5ca0aada2111fcbe550a90fed04d1c634bd31a14
Deleted: sha256:02b80ac2055edd757a996c3d554e6a8906fd3521e14d1227440afd5163a5f1c4
Deleted: sha256:b92aa5824592ecb46e6d169f8e694a99150ccef01a2aabea7b9c02356cdabe7c
Deleted: sha256:780238f18c540007376dd5e904f583896a69fe620876cabc06977a3af4ba4fb5
Untagged: redis:latest
Untagged: redis@sha256:db485f2e245b5b3329fdc7eff4eb00f913e09d8feb9ca720788059fdc2ed8339
Deleted: sha256:7614ae9453d1d87e740a2056257a6de7135c84037c367e1fffa92ae922784631
Deleted: sha256:49c70179bc923a7d48583d58e2b6c21bde1787edf42ed1f8de9e9b96e2e88e65
Deleted: sha256:396e06df5d1120368a7a8a4fd1e5467cdc2dd4083660890df078c654596ddc1c
Deleted: sha256:434d118df2e9edb51238f6ba46e9efdfa21be68e88f54787531aa39a720a0740
Deleted: sha256:2047f09c412ff06f4e2ee8a25d105055e714d99000711e27a55072e640796294
Deleted: sha256:13d71c9ccb39b206211dd1900d06aa1984b0f5ab8abaa628c70b3eb733303a65
Deleted: sha256:2edcec3590a4ec7f40cf0743c15d78fb39d8326bc029073b41ef9727da6c851f
Untagged: centos:7
Untagged: centos@sha256:9d4bcbbb213dfd745b58be38b13b996ebb5ac315fe75711bd618426a630e0987
Deleted: sha256:eeb6ee3f44bd0b5103bb561b4c16bcb82328cfe5809ab675bb17ab3a16c517c9
Deleted: sha256:174f5685490326fc0a1c0f5570b8663732189b327007e47ff13d2ca59673db02

第二种方法:

命令 docker image prune -a

[root@harbor <sub>]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
redis v1 07d6e5a00daa 2 weeks ago 109MB
nginx latest 605c77e624dd 3 months ago 141MB
redis latest 7614ae9453d1 3 months ago 113MB
centos 7 eeb6ee3f44bd 7 months ago 204MB
centos latest 5d0da3dc9764 7 months ago 231MB
[root@harbor </sub>]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
03859aec2881 nginx:latest "/docker-entrypoint.…" 3 minutes ago Up 3 minutes 80/tcp nginx
[root@harbor ~]# docker image prune -a
WARNING! This will remove all images without at least one container associated to them.
Are you sure you want to continue? [y/N] y
Deleted Images:
untagged: centos:7
untagged: centos@sha256:9d4bcbbb213dfd745b58be38b13b996ebb5ac315fe75711bd618426a630e0987
deleted: sha256:eeb6ee3f44bd0b5103bb561b4c16bcb82328cfe5809ab675bb17ab3a16c517c9
deleted: sha256:174f5685490326fc0a1c0f5570b8663732189b327007e47ff13d2ca59673db02
untagged: redis:v1
deleted: sha256:07d6e5a00daa386ed5117d7bf7751f74b46f5831aea69036580cd509bb6781e7
deleted: sha256:7c4045019efba50b56d30912599164ec3e5422537e152f01d08b3e3556b86919
untagged: centos:latest
untagged: centos@sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
deleted: sha256:5d0da3dc976460b72c77d94c8a1ad043720b0416bfc16c52c45d4847e53fadb6
deleted: sha256:74ddd0ec08fa43d09f32636ba91a0a3053b02cb4627c35051aff89f853606b59
untagged: redis:latest
untagged: redis@sha256:db485f2e245b5b3329fdc7eff4eb00f913e09d8feb9ca720788059fdc2ed8339
deleted: sha256:7614ae9453d1d87e740a2056257a6de7135c84037c367e1fffa92ae922784631
deleted: sha256:49c70179bc923a7d48583d58e2b6c21bde1787edf42ed1f8de9e9b96e2e88e65
deleted: sha256:396e06df5d1120368a7a8a4fd1e5467cdc2dd4083660890df078c654596ddc1c
deleted: sha256:434d118df2e9edb51238f6ba46e9efdfa21be68e88f54787531aa39a720a0740
deleted: sha256:2047f09c412ff06f4e2ee8a25d105055e714d99000711e27a55072e640796294
deleted: sha256:13d71c9ccb39b206211dd1900d06aa1984b0f5ab8abaa628c70b3eb733303a65

以上是关于Docker镜像管理的主要内容,如果未能解决你的问题,请参考以下文章

docker镜像管理基础

docker镜像管理基础

Docker------Docker基本管理

Docker 镜像-管理-导入-导出

Docker------Docker基本管理(镜像,容器,网络,资源控制)

Docker 镜像之存储管理