Skip to main content

Installing Docker Images from private repositories in Docker Swarm

Installing Docker Images from private repositories in Docker Swarm

Introduction

On a Docker Swarm you can deploy only those images which come from a Docker repository as all the manager/worker nodes need to pull them separately.
When the Docker images are pulled from public repository like DockerHub they can be easily deployed using a simple command such as
docker service create nginx
and if you happen to use compose file you can use
docker stack deploy -c "name of the compose file".

However in the case of private repositories you need to provide Docker credentials and Docker repository details too.

In this tutorial, I will list out the steps needed for deploying Docker images from a DockerHub private repository.

Login to DockerHub

Considering that you have a substantial number of images and using a Docker-compose file where you have listed the Docker images needed from private repositories.The first step would be is to log on to DockerHub from all nodes(manager and worker)
Use this command docker login and input your username and password.
The reason why this step is important (in my experience) is that we might want to use the deploy constraint available in docker compose(see below) to run Docker containers only on worker nodes. I believe in this cases the Docker pull is ran from worker machines only and that is why it is essential to log in on worker nodes. Not logging from worker nodes in this scenario failed to pull images for me in Worker nodes.

Deploying images on Swarm

When deploying on Swarm you need to run the following command, considering that you have created a compose file

Breaking above command for clarification

  • -u #DockerHub Username# : The DockerHub Username
  • -p #DockerHub Password#: The DockerHub Password
  • #Organization-Or-DockerHubUserName#: In case you have created a team/organisation on DockerHub and you have pushing images like organisation/Docker-Image. This is a scenario where you can have multiple team members working on same Docker image and pushing the image using something like TEAM/DockerImage.In case you are a single user and don’t have any Team defined in DockerHub you can use username
  • #STACK-NAME#: The stack name, could be just a “test” or something more meaningful name suited to requirement
  • –with-registry-auth: This option tells that you are pulling images from a docker hub registry with authorization.

a simple example of above command would be like

Related Posts

2 thoughts on “Installing Docker Images from private repositories in Docker Swarm

Leave a Reply

Your email address will not be published. Required fields are marked *

Bitnami