Save and load Docker images locally
Posted: | Tags: til dockerWhile trying to test recovery of a service from a backup, as everyone should, I discovered a container image was no longer available from Docker Hub anymore. I was greeted by the following error:
ERROR: The image for the service you're trying to recreate has been removed. If you continue, volume data could be lost. Consider backing up your data before continuing.
Continue with the new image? [yN]
Since I had a perfectly healthy and running instance of the service on my homelab which I could use to save the image from that I could then include in my backup copy.
Saving containers
Once you have an image pulled locally you have to save the image using docker save
. Set the desired output file name using the --output
parameter. You can also pick a specific version using the image tag.
docker save --output jboss-keycloak.tar jboss/keycloak
Loading containers
Once the tar file was created, you can store this alongside your backup copies. The image can be loaded from the tar file to be used. Use the --input
parameter to specify the file
docker load -i jboss-keycloak.tar
Once loaded you can verify using the images
command.
docker images
Running your own registry?
Running a local registry seems like too much effort at the moment, at least for this use case. I can simply update my backup scripts to save the Docker image on the first backup rather than having to worry about setting up a new registry service. Dom Corriveau has written more about using Forgejo’s container registry and automating local copies. It’s worth a read if the local registry route is more appealing.