Docker Swarm Registry Service
From my previous post, Docker Swarm Offline, working with Docker Swarm offline was a bit tricky because it meant manually pushing images around from node to node.
The solution: run a registry service within the swarm! All images available on the registry would be available to swarm nodes in this configuration. It’s like having a private docker hub!
- Setting up the registry service
- Push images to registry service
- Deploy service to nodes
- Verify service locations
If you would like to follow along, please:
- Install Virtualbox
- Install vagrant
- Download this Vagrantfile to your local folder and modify this line:
- From the local folder where the Vagrantfile is, run:
$ vagrant upto create virtual computers: manager and worker1.
Working on Multiple Nodes
Through this article, there will be connections between systems,
manager and worker1 to verify. To connect to different systems using
the Vagrantfile configuration, run:
$ vagrant ssh <system>.
For example, to connect to the manager node, from the host, run:
vagrant ssh manager. Similarly for worker1:
$ vagrant ssh worker1.
Ensure Clean Slate
Let’s start with no images on any of the nodes connected to the swarm,
$ docker rmi <image name> to get rid of any images. You may need
On manager node, use
$ docker images and
$ docker ps to check
there are no images or containers running:
Similarly on worker1 node:
Just to double check, use
$ docker service list to ensure no
services running on the swarm:
With a clean slate, get two images: nginx and registry. We use the nginx image as a simple application image and the registry as the registry service:
With these two images, you can disconnect your host computer from the network and the rest of the article will be more impressive.
Create Registry Service
On the manager node, use the:
$ docker service create to start the
Note the message:
image registry:latest could not be accessed on a registry to record its digest. Each node will access registry:latest independently, possibly leading to different nodes running different versions of the image.
Appears because the host system is offline. This does not appear if the host system is online.
With the registry service running in the Swarm, let’s test it out.
Check Registry Service
With the registry service running, let’s check it’s status using the
$ docker service ls and
$ curl command from the manager node and
Perfect, looks like the registry service is running and available to manager and worker1 nodes. Wasn’t that simple?
Populating Registry Service
An empty registry is not useful, so let’s take the nginx image on the manager node and push to the local registry so we can make a service using it.
First step in pushing the image: re-tag the nginx image using the
docker tag <image name> <host/new image name> command.
With the image tagged:
localhost:5000, let’s push it using the
docker push command:
Ok, with that setup complete, let’s create a service!
Create Service from Local Registry
Using the local registry and command:
$ docker service create
command, let’s get the nginx service on the Swarm:
Looks normal, where is it running? Let’s check using
$ docker service
$ docker service ps:
Oh wow, the worker1 node is already running the application? There was
no need to copy the image over, Docker Swarm automagically copied the
image over via the local registry, let’s check on worker1 using the
docker images command:
Without any work on our part. The image showed up on there, like magic!
Running the Docker registry as a service in a Swarm enables a private registry, which allows services to be easily started on any node within the Swarm only requiring the image to be on the registry. Docker Swarm will copy over the image to the node auto-magically.