docker - 删除了 Docker 镜像,如何从容器中创建新镜像?

标签 docker

我不小心删除了我机器上的所有 docker 镜像 docker rmi <imgid> -f但幸运的是容器完好无损。当我尝试使用 docker commit 575985d354ef ubuntu_16_10:dsktop 从容器创建图像时它给出以下错误:

Error response from daemon: open /var/lib/docker/image/overlay2/imagedb/content/sha256/f31173ea77a68f70d897dba7623010a0471fa566a106c24a0e616278d37482e9: no such file or directory

如何从现有容器创建新镜像?

最佳答案

您不应该能够删除正在运行的容器使用的镜像:

$ docker run --name nginx-test -d nginx
351eb0e3a96b4375176358581a0afb460f57775382928860af764eb9d5e33b25

$ docker image rm nginx
Error response from daemon: conflict: unable to remove repository reference "nginx" (must force) - container 351eb0e3a96b is using its referenced image 5e69fe4b3c31

因此,如果您成功删除了镜像,那么您也破坏了容器,因为 docker 使用分层文件系统,重用容器 RW 层下的镜像层。这就是说图像层不会为每个容器复制的技术方式。

您需要重建您的形象。现在是考虑使用 Dockerfile 而不是手动创建容器并提交结果的好时机。

关于docker - 删除了 Docker 镜像,如何从容器中创建新镜像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43914925/

相关文章:

docker - Docker swarm-manager显示旧容器信息

Docker:禁用特定阶段的缓存

docker - 通过 FROM 从不同的本地目录导入 Dockerfile

docker - 无法使用python uwsgi运行docker容器

docker - 将文件添加到隐藏文件夹

macos - Docker-提供了但未定义的标志:-发布

python - 尝试从外部Python连接到Docker中的SQL Server

docker - 如何在Dockerfile中设置账户密码?

docker - 在构建自己的容器的 Jenkins 管道中获取 "sudo: unknown uid xxx: who are you?"

docker - 在Bash中检查Docker实例