I was wondering if it is possible to manually extract a docker image to the /var/lib/docker directory and load it this way, without actually using docker load.
I’m doing a custom build that uses chroot, which makes it virtually impossible to start the docker daemon and use docker load, so I’m looking for other ways to load the image.
I have also tried copying the entire /var/lib/docker/vfs and /var/lib/docker/images folders, but it seems that there are special files which can’t be copied.
Is there any other way?
For anyone else who might be looking, I think I found a solution for moving an image without using docker load:
-
Add {“data-root”: “/path/to/your/docker”} in /etc/docker/daemon.json on a regular machine running docker.
Note that the directory needs to be your build folder, in the exact location (/var/lib/docker) where it will be once the build is completed.
-
systemctl restart docker
-
Pull or load the image you’re trying to include in your build.
What happens is that docker will recreate (or move?) the entire /var/lib/docker folder structure to the directory specified in data-root of the daemon.json.
Since you put it in your build folder, you should now be able to complete the build and use this “copy” of /var/lib/docker with all the folders holding the image layers, hopefully enabling you to run the container.
I’ll check if this works and report back.
Yes, I can confirm it works this way.
One thing I noticed is that the images need to be writable before the container is started, which I didn’t expect. So if you’re doing a live boot, the images will be automatically copied to the overlay fs first before the container starts. Gonna try around a bit more if I can get around that.