Recovering a docker setup with just /var/lib/docker available?

Unfortunately, the system main partition is apparently gone with a disk failure.
/var is mounted elsewhere and should be still accessible, so I thought I could still recover the docker setup from /var/lib/docker directory. I made a simulation on another machine:

  • I created and launched a container
  • I stopped dockerd and containerd
  • I backed up /var/lib/docker
  • I purged the docker installation
  • I made a new fresh install of docker
  • with dockerd and contained stopped I replaced the brand new /var/lib/docker directory with the previous one
  • I started containerd and dockerd
  • unfortunately docker ps gave no container available (even with -a option)
  • as well docker images gave no images available

My understanding of docker matters is still limited, but in my condition perhaps you may understand I’m in a hurry to recover some precious data. Can I rely on what I have still available only? If that is the case, what is the proper procedure to see again the containers?

Thanks in advance!

Andrea

In theory, it should be sufficient to backup and restore /var/lib/docker as long as
– the os is the same on source and target system
– the filesystem /var/lib/docker is identical on source and target system
– the cpu architecture is identical on source and target system
– the docker version is the same on source and target system
– you didn’t use bind-mount volumes (which mount a host folder into a container folder)

#2 is cruical: make sure the Storage Driver remains the same, otherwise existing image and container data could be ignored by a different Storage Driver.

May I ask how you did the backup of /var/lib/docker?

1 Like

Hello!
I guess conditions from #1 to #5 should be automatically satisfied since what I have in mind is just replacing the broken disk, and installing in the new working one the same OS as before and the same docker version, tentatively leaving /var where the fresh installation creates it and putting a symbolic link to the old /var/lib/docker directory in place of the corresponding brand new /var/lib/docker directory. As for #2 I may assume the storage driver shouldn’t change with the freshly installed docker, since I didn’t make any custom configuration for that in the past, so the default should fit. As for #6: how can I know whether that is my case without delving into a subject where I’m pretty ignorant? Hoping this can help: I used a peaceful standard ubuntu installation that has been dropped there with some .deb file…

I’m not sure what you mean with the backup of /var/lib/docker… The original precious data are still there in the partition that was supposed to be mounted on /var, so I didn’t have to back them up, that stuff is on drives still working. As for the failed simulation I did on another machine, I simply used tar or cp or mv - I can’t recall exactly - to keep for later the docker data directory where a container was created. The expected result was the docker installed from scratch should see the dummy container created with the previous installation, after replacing the brand new /var/lib/docker directory with the previously filled one. As I wrote, unfortunately, the freshly installed docker does not see the previously generated container.

I really hope I won’t miss something I cannot recover anymore. Apparently, the only configurations or data are in /etc/docker (containing just key.json) and in /var/lib/docker…

Thanks anyway!

Andrea

I strongly suggest to create the file /etc/docker/daemon.json and configure the new folder as root-data folder instead. A forum search for “root-data” should provide plenty of helpful hits about how its done.

It realy depends on what features the kernel provides and what filesystem is used, unless specificly configured otherwise. Since the system is used as is, the kernel part should be safe, though the filesystem is cruicial, especialy if no custom configuration was done.

See: Docker storage drivers | Docker Docs for which Storage Driver is supported on which filesystem.

This pretty much depends on how the container are created. Every volume declaration that starts with a relative or absolut path is a bind-mount. Of course such data will not be stored in the /var/lib/docker folder.

Tar and mv should be fine when it commes to preserving ownership and permissions… cp not so much.

I did succeed in restoring the original setup. Though tentatively I still use a copy of /var/lib/docker
in an external drive, specifying the corresponding location in /etc/docker/daemon.json, as you suggested.

Many thanks!

Andrea