zl程序教程

您现在的位置是:首页 >  工具

当前栏目

Docker镜像管理常用

Docker镜像 管理 常用
2023-09-14 09:15:55 时间

docker镜像管理命令

镜像管理命令说明
docker images查看本机镜像
docker search 镜像名称从官方仓库查找镜像
docker pull 镜像名称:标签下载镜像
docker push 镜像名称:标签上传镜像
docker save -o 备份镜像名称.tar 镜像名称:标签备份镜像为tar包
docker load -i 备份镜像名称导入备份的镜像文件
docker rmi 镜像名称:标签删除镜像(必须先删除该镜像启动的所有容器)
docker history 镜像名称:标签查看镜像的制作历史
docker inspect 镜像名称:标签查看镜像的详细信息
docker tag 镜像名称:标签 新的镜像名称:新的标签创建新的镜像名称和标签

在这里插入图片描述


查看镜像的构建步骤

https://blog.csdn.net/omaidb/article/details/122044116


查看镜像的详细信息

# 查看镜像的详细信息
docker inspect 镜像名

导出镜像

# 将ubuntu:latest镜像导出到当前目录
docker save ubuntu:latest -o ubuntu-latest.tar

导入镜像

# 将ubuntu-latest.tar镜像导入
docker loda -i ~/ubuntu-latest.tar

# 查看镜像
docker images

修改镜像tag

# 查看本地镜像
[rhel8 root ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED       SIZE
hello-world   latest    feb5d9fea6a5   5 weeks ago   13.3kB

# 修改镜像
## docker tag 镜像名称:标签 新的镜像名称:新的标签	
[rhel8 root ~]# docker tag hello-world:latest hello-world:test
# 查看镜像
[rhel8 root ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED       SIZE
hello-world   latest    feb5d9fea6a5   5 weeks ago   13.3kB
hello-world   test      feb5d9fea6a5   5 weeks ago   13.3kB

清理损坏镜像

# 清理损坏的镜像
[c8 root ~]# 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

清理所有未使用镜像

# 清理所有未使用镜像
docker image prune -a

在这里插入图片描述


清理未使用容器/数据卷/镜像

# 删除所有退出状态的容器(包括非docker容器)
docker container prune

# 删除未被使用的数据卷
docker volume prune

# 删除 dangling 或所有未被使用的镜像
docker image prune

在这里插入图片描述


清理所有未使用的资源

删除已停止的容器dangling 镜像、未被容器引用的 network 和构建过程中的 cache

参考: https://www.cnblogs.com/sparkdev/p/9177283.html

# 清理所有未使用的资源(不清除存储卷)
docker system prune --all

# 清理所有未使用的资源(清理未使用的存储卷)
docker system prune --all --force --volumes

显示docker磁盘使用情况

参考: 显示docker磁盘使用情况

# 显示所用数据的摘要
docker system df

# 详细试图
docker system df -v

在这里插入图片描述


Docker学习笔记

花了很长时间总结的Docker学习笔记,
想要这个docker学习笔记的.xmind文件可以在下方留言,我把笔记传上来。

在本博客学习docker,配合精心制作的docker笔记,学习效果更佳
https://download.csdn.net/download/omaidb/12581323

在这里插入图片描述