SACn
SACn

Reputation: 1924

Deleted Docker Image, How to Create New from Container?

I've accidentally deleted all docker images on my machine with docker rmi <imgid> -f but fortunately had container intact. When i try to create image from container using docker commit 575985d354ef ubuntu_16_10:dsktop it gives following error:

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

How to create a new image from containers present ?

Upvotes: 2

Views: 1257

Answers (1)

BMitch
BMitch

Reputation: 265200

You shouldn't be able to delete the image used by a running container:

$ 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

So if you managed to delete the image, you've also broken the container since docker uses a layered filesystem, reusing the image layers under the containers RW layer. That's the technical way of saying the image layers are not copied for each container.

You'll need to rebuild your image. Now would be a good time to consider using a Dockerfile instead of creating containers by hand and committing the results.

Upvotes: 2

Related Questions