0

I made a goof while trying to rename an image by following the steps on this page that say to create a tag then delete the original Docker how to change repository name or rename image?

Now when I list the images it doesn't show up anymore. However, when I list the containers the image still shows up.

PS C:\Users\Grail> docker images -a
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              latest              157be28c0fe3        7 days ago          668MB
fedora              latest              a368cbcfa678        2 months ago        183MB
PS C:\Users\Grail> docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      
1ea5ffd50852        157be28c0fe3        "/bin/bash"              7 hours ago         Exited (0) 7 hours ago                          
fb81990e756c        0d120b6ccaa8        "/bin/bash"              10 hours ago        Exited (0) 24 minutes ago                       
081641b3e600        a368cbcfa678        "/bin/bash"              11 hours ago        Exited (0) 31 minutes ago                       

Not only that, the image (0d120b6ccaa8) still shows up in my Docker Dashboard (running on Windows) and I can start/stop it without any problems.

  1. Clearly the image still exists. Can I restore it such that I can see it when I list the images?
  2. Can it be restored from the container?
  3. If it's in a weird state/unrecoverable, how do I actually delete it so it's not taking up space?

Update:

Thanks to @prashanna I went down a path where I exported the container and imported to get the image:

docker export -o mycontainer.tar fb81990e756c

docker import mycontainer.tar

stackbacker
  • 329
  • 2
  • 11
  • It seems you need `docker commit`, it can be useful to commit a container's file changes or settings into a new image. – Vox Sep 23 '20 at 03:43
  • You should be able to `docker pull` or `docker build` the image again. The state you're in isn't consistent, though; how did you delete the image, and does `docker images` (without the `-a` option and without filtering out `` lines) really not include it? – David Maze Sep 23 '20 at 11:49

1 Answers1

0

**docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]**

is for creating a new image from a container, meaning when you update or add new config or install new software, thus creating a new template images.

ref:docker commit

Prashanna
  • 889
  • 1
  • 8
  • 13
  • I tried this but got an error. Not sure why it's looking at a linux path: PS C:\Users\Marc> docker commit fb81990e756c ubuntu Error response from daemon: failed to get digest sha256:0d120b6ccaa8c5e149176798b3501d4dd1885f961922497cd0abef155c869566: open /var/lib/docker/image/overlay2/imagedb/content/sha256/0d120b6ccaa8c5e149176798b3501d4dd1885f961922497cd0abef155c869566: no such file or directory – stackbacker Sep 23 '20 at 04:05
  • try "docker commit fb81990e756c ubuntu:stackbeacker" – Prashanna Sep 23 '20 at 04:08
  • Didn't work....ended up exporting container & importing it. – stackbacker Sep 23 '20 at 04:12
  • Note that `docker commit` is almost never a best practice. In this particular situation, if you have a hand-crafted container that you really can't recreate any other way, it's a way out, but this should be a warning that you need a Dockerfile or some other way to reproducibly recreate the image. – David Maze Sep 23 '20 at 11:51