After you’ve been developing your code using docker there will inevitably come a time when you’d like to share your workspace (code and all!) with someone else or put it on another computer.
A small little foray into Google will tell you that there is a docker command
called docker save
that will let you do just that.
But don’t! (Please don’t.)
There’s a better way that doesn’t involve compressing an entire disk image!
Docker images are really meant to be transferred through a Docker Registry.
You could set one up on a cloud service (AWS, GCloud, or even git lets you do this!)
But if you intend on transferring the image inside of the same network, seriously consider using a local docker registry.
Why?
It’s a really simple one-line command.
docker run -d -p 5000:5000 --restart always --name registry registry:2
Yep, that’s it!
Now your computer will run a docker registry, even if you restart your computer.
For any other machine on your local network that you’d like to use the docker registry for, all you need to do is set up the docker daemon to use it.
Since it’s a local registry, it doesn’t have the security (https) that remote registries do. So we will need to add it to the exception list so that we’ll be allowed to pull from it.
Edit the /etc/docker/daemon.json
to have the following line
{ "insecure-registries": ["your_hostname.local:5000"] }
Replace ‘your_hostname’ with the hostname of the computer you set up as the local docker registry or its IP address.
Note
your_hostname.local
uses avahi to resolve the appropriate IP address. This is normally preferred since routers typically dynamically assign IP addresses and this lets you reference a specific device without having to know what the IP address is, and without having to update it. If avahi doesn’t work on your network for some reason, you can replaceyour_hostname.local
with an IP address.
Pushing to a local Docker Registry is as easy as tagging an image with the registry name (the hostname or IP of your registry + port number) and pushing.
For example:
docker tag your_docker_image your_hostname.local:5000/your_docker_image
docker push your_hostname.local:5000/your_docker_image
Pulling is similarly simple.
docker pull your_hostname.local:5000/your_docker_image
That’s it!
All the layers are appropriately cached so incremental updates should be fast!