In an upcoming article, I will set up a local registry for Docker
Swarm so every node on the swarm will be using the same image, even
when working offline - or one can have their own secret images in the
This article will go over how to work with Docker registry locally.
With the local registry, how to:
check for stored images
tag image for pushing
I will also go over what happens when the registry is not running.
to your local folder and modify this line:
Run $ vagrant up manager - which will create a virtualbox with necessary software
login using $ vagrant ssh manager
All the following commands are from within this computing environment.
Run a Local Registry
After logging into the manager node, let’s get the registry
And get the registry running with command:
Interacting with the Local Registry
Test the local registry using curl commands: curl
Awesome, this means the local registry is working and there’s nothing
in its repository.
Push image to Local Registry
Let’s take an existing image, the nginx image, retag it for the
local registry and push it with the following commands:
docker tag <image name> <host/new image name>
docker push <host/new image name>
Let’s check what the local registry says now:
Great, the new image, nginx-v1 is on the local repository.
Removing Local Docker Image
Now, let’s test out how the Local Registry can work. If you can,
disable networking to your computer for the next steps as you follow
along. This is what will happen:
remove the local image that’s also on the local repository (in this
case, it’s localhost:5000/nginx-v1), using command: docker rmi
start a container that uses the image on the local repository, which
will be localhost:5000/nginx-v1, using command: docker run
Pulling from Local Registry
With the localhost:5000/nginx-v1 image removed from the manager
machine, let’s pull from the local repository:
Now, this doesn’t seem so impressive, but if you were offline for
these steps, it should be.
This means the local registry can serve any image that’s pushed to it,
without a network connection.
For a single machine, it’s nothing, but when there’s networked
machines that is only connected to a single repository, this can get
pretty useful behind firewalls, VPC, etc.
Remove Local Registry
Now, stop the local registry container, using the docker stop
command, this is what would happen after removing the local image:
Now without a localhost:5000/nginx-v1 image locally, and stopping
the local registry container. Let’s see what happens when trying to
run: docker pull localhost:5000/nginx-v1 like before:
Wow, so the command: docker pull localhost:5000/nginx-v1 connects
with the local repository.
Deleted Registry, Deleted Images
Beware: when stopping the local registry container, this will delete
the images stored on the local registry.
We have gone over how to create a local Docker registry using the
Docker registry image, testing it out via curl commands, pushing and
pulling images to/from it and what happens when the registry is down.
Look for an upcoming article where I use the Docker Registry to help
deploy images to each node on a Docker Swarm.