我不小心删除了我机器上的所有 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/