Home > database >  How to recover docker images and containers from a backup of /var/lib/docker
How to recover docker images and containers from a backup of /var/lib/docker

Time:09-21

I had a corrupted OS of Ubuntu 16, and I wanted to backup all the docker things. Starting docker daemon outside fakeroot with --data-dir= didn't help, so I made a full backup of /var/lib/docker (with tar --xattrs --xattrs-include='*' --acls).

And in the fresh system (upgraded to Ubuntu 22.04), I extracted the tar, but found docker ps having empty output. I have the whole overlay2 filesystem and /var/lib/docker/image/overlay2/repositories.json, so there may be a way to extract the images and containers, but I couldn't find one.

Is there any way to restore them?

CodePudding user response:

Probably not , as far as I have learned about docker it has stored your image in form different layers with different sha256 chunks.

Even when you try to transfer the images from one machine to another you would require online public/private repository to store and retrieve images or you have to zip the files from command line and then you can copy and paste it another location as single file.

Maybe from next time make sure you store all your important images to any of the online repository.

You can also refer different answers from this thread : How to copy Docker images from one host to another without using a repository

CodePudding user response:

The backup worked actually, it was due to the docker installed during Ubuntu Server 22.04 installation process was ported by snap. After removing snap and installing a systemd version, the docker did recognize all the images and containers in overlayfs. Thanks for everyone!

For those who cannot start docker daemon for backup, you can try cp -a or tar --xattrs-include='*' --acls --selinux to copy the whole /var/lib/docker directory.

  • Related