Deploying in Docker Swarm From a Private Repository

How to deploy docker services in swarm using a private repository

By default Docker Swarm pull images from Docker Hub, but sometimes we want to have our own private repositories and private images. Then, a few things have to be changed to allow it.

In this guide, I will show you how to do it, by using the example of GitLab repositories.

Lets assume that we have our private images in GitLab and we have already deployed a swarm stack called example-project.

The first thing you need to do is:

docker login <gitlab-url>:<repository-port>

You will need to check the port with your GitLab or repository provider, a common used port in GitLab is 4567.

Then you will be asked to provide your username and password. The password is often a token or a secure key you have created only for accessing to your private repository.

Finnaly, you can deploy your stack as always by adding the option --with-registry-auth.

docker stack deploy -c docker-compose.yml example-project --with-registry-auth

Related