主题
Docker 镜像(Image)
只读模板,用于创建容器。通常来自 Registry 或本地 Dockerfile 构建。
高频命令
bash
# 获取与查看
docker image pull nginx:latest # 拉取镜像
docker image ls # 查看本地镜像
# 构建与发布
docker image build -t my-app:latest . # 使用当前目录构建镜像
docker image tag my-app:latest registry.example.com/my-app:1.0 # 添加仓库标签
docker image push registry.example.com/my-app:1.0 # 推送镜像
# 删除与清理
docker image rm my-app:latest # 删除指定镜像标签
docker image prune -af # 清理所有未被容器使用的镜像备份 / 恢复
bash
# 备份镜像
docker tag xxx:latest xxx:2.7.2 # 添加版本标签
docker save -o xxx_2.7.2_backup.tar xxx:2.7.2 # 导出镜像
# 恢复镜像
docker load -i xxx_2.7.2_backup.tar # 导入镜像