Docker的镜像基础管理

root
233
文章
0
评论
2020年5月7日13:55:53 评论 2842字阅读9分28秒

Docker的镜像基础管理

基础镜像拉取

docker pull centos

docker pull centos:6.3

docker pull centos:7.0

docker pull nginx

镜像的基础查看

查看下载的所有镜像

docker imager ls

查看下载的所有进行的ID号码

docker imager ls -p

查看镜像的详细信息

docker image inspect 镜像名

查看docker所有模块占用磁盘的空间

docker system df

查看指定镜像的所在位置下面的镜像

docker image ls -f before=nginx:1.15

[root@hwf ~]# docker image ls 
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               1.16                dfcfd8e9a5d3        13 days ago         127MB
nginx               1.17                602e111c06b6        13 days ago         127MB
nginx               1.15                53f3fd8007f7        12 months ago       109MB
[root@hwf ~]# docker image ls -f before=nginx:1.16
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               1.17                602e111c06b6        13 days ago         127MB
nginx               1.15                53f3fd8007f7        12 months ago       109MB
[root@hwf ~]# docker image ls -f before=nginx:1.17
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               1.15                53f3fd8007f7        12 months ago       109MB

查看指定镜像的所在位置上面的镜像

docker image ls -f since=hello-world:latest

[root@hwf ~]# docker image ls 
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               1.16                dfcfd8e9a5d3        13 days ago         127MB
hello-world         latest              bf756fb1ae65        4 months ago        13.3kB
[root@hwf ~]# docker image ls -f since=hello-world:latest 
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               1.16                dfcfd8e9a5d3        13 days ago         127MB

 

镜像的导入和导出

复制导入镜像到指定位置

docker imger save nginx >/opt/nginx.tar.gz

 docker imager save 43458646b2 >/tmp/ubu.tar.gz   [这里使用镜像名:版本,不要使用ID,不然为none]

 

导入镜像

docker image load -i /tmp/ubbu.tar.gz

shell 批量导出镜像包

# 批量导出

for x in $(docker images --format "{{.Repository}}:{{.Tag}}");do docker save ${x} > devops-images/${x##*/}.tgz ;done;

 

for x in $(docker images --format "{{.Repository}}:{{.Tag}}" | grep c7n/hzero-);do docker save ${x} > images/${x##*/}.tar ;done;

 

#批量删除

 for x in $(docker images --format "{{.Repository}}:{{.Tag}}"|grep goharbor/);do docker image rm -f ${x} ;done;

举例

for x in $(docker images --format "{{.Repository}}:{{.Tag}}" | grep registry.c7n.gzinfo);do echo ${x##*/} ;done;

导出猪齿鱼官方镜像

for x in $(docker images --format "{{.Repository}}:{{.Tag}}" | grep registry.cn-shanghai.aliyuncs.com/c7n);do \
if [ ! -f "/data/images/${x##*/}.tar" ];then \
docker save ${x} > /data/images/${x##*/}.tar ; \
fi \
done;
##*/ - 最右边"/"开始 左边删除,保留右边
#*/  - 最左边"/"开始 左边删除,保留右边
%%/* - 最左边"/"开始 右边删除,保留左边
%/*  - 最右边"/"开始 右边删除,保留左边

批量导入镜像包

for x in $(ls *.tar);do docker load -i ${x};done

 

镜像的删除(如果容器使用了,先删除容器在删除镜像)

删除镜像

docker image rm -f 43458646b2

删除全部镜像

docker image rm -f `docker image ls -q`

虚悬镜像

这类无标签镜像也被称为 虚悬镜像(dangling image) ,

上面的镜像列表中,还可以看到一个特殊的镜像,这个镜像既没有仓库名,也没有标签,均为 <none>

可以用下面的命令专门显示这类镜像:

查看虚悬镜像

[root@hwf ~]# docker image ls -f dangling=true
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

删除虚悬镜像

docker image prune

[root@hwf ~]# docker image prune
WARNING! This will remove all dangling images.
Are you sure you want to continue? [y/N] y
Total reclaimed space: 0B

 

镜像添加标签tag

给没有标签的镜像打上标签

docker image tag 镜像ID号 xxx:xxx

[root@hwf ~]# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               1.16                dfcfd8e9a5d3        13 days ago         127MB
nginx               latest              602e111c06b6        13 days ago         127MB
hello-world         latest              bf756fb1ae65        4 months ago        13.3kB
[root@hwf ~]# docker image tag 602e111c06b6 xxx:1.1
[root@hwf ~]# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               1.16                dfcfd8e9a5d3        13 days ago         127MB
nginx               latest              602e111c06b6        13 days ago         127MB
xxx                 1.1                 602e111c06b6        13 days ago         127MB
hello-world         latest              bf756fb1ae65        4 months ago        13.3kB

如果要保留这个标签,可以将原先的标签名称删除

 

继续阅读
weinxin
我的微信
这是我的微信扫一扫
  • 文本由 发表于 2020年5月7日13:55:53
  • 除非特殊声明,本站文章均为原创,转载请务必保留本文链接
Harbor镜像仓库 Docker

Harbor镜像仓库

Harbor镜像仓库 一、Harbor特性介绍 基于角色访问控制 每个人角色不同,需求也不同,因此就需要访问权限控制,根据角色分配相应的权限。例如,开发人员需要对项目构建这就需要用到读写权限(push...
Centos7解决systemctl无法使用 Docker

Centos7解决systemctl无法使用

systemd整合: 因为systemd要求CAPSYSADMIN授权,从而得到了读取到宿主机cgroup的能力,Centos7中已经用fakesystemd代替了systemd来解决依赖问题。如果仍...
Dockaer网络 Docker

Dockaer网络

Dockaer网络 docker本地网络类型 查看本地支持网络类型 docker network ls # docker network ls NETWORK ID NAME DRIVER SCOPE...
Dockerfile练习 Docker

Dockerfile练习

Dockerfile练习 实验一:要求使用centos7基础镜像,搭建httpd+sshd+php的镜像,实现httpd与sshd服务能够正常访问 创建存放dockerfile的目录 mkdir -p...
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: