GitLab Container Registry as an alternative to Docker Hub

GitLab is not only a great code repository but also comes with powerful continuous integration/deployment (CI/CD) features to make it your one place to manage and build software projects. Last year they introduced the GitLab Container Registry to make the puzzle even more complete. As we got a lot of requests if it possible to deploy docker images to sloppy.io hosted by the GitLab Container Registry I thought it is time for a blog post, so here we go.

In this quick how-to, I will show you using the GitLab Container Registry for your docker images and how easy it is to deploy them to sloppy.io.

First, sign up for a free account at https://gitlab.com/users/sign_in and create a new project:

 

Let’s name it “cool-website” and you will be redirected to your new project page with a tab called “Registry”. Click it and you will find all the information you need to work with your GitLab Container Registry.

 

 

Now login using the docker CLI and your GitLab credentials. NOTE:  If you used Google, Twitter or another OAuth method to sign up you need to add a password at https://gitlab.com/profile/password/edit to make login with the docker CLI work.

docker login registry.gitlab.com

For the sake of simplicity, I take an existing docker image I already have on my workstation. If you don’t have one or want to follow exactly this how-to, do docker pull nginx:alpine to get the official nginx image. Type docker images to list your images:

# docker images
REPOSITORY                          TAG                 IMAGE ID            CREATED             SIZE
mikemichel/fimply                   0.1                 2886775b372b        8 days ago          58.56 MB
mikemichel/fimply                   latest              2886775b372b        8 days ago          58.56 MB
nginx                               alpine              bedece1f06cc        2 weeks ago         54.27 MB

Ok, first I take nignx:alpine and re-tag it so docker push afterwards knows that it needs to upload the image to the GitLab Container Registry:

docker tag nginx:alpine registry.gitlab.com/mike49/cool-website/nginx:alpine

docker push registry.gitlab.com/mike49/cool-webiste/nginx:alpine
The push refers to a repository [registry.gitlab.com/mike49/cool-website/nginx]
e6983b701b8b: Pushed
90e9f0ac3473: Pushed
9f654519d2ae: Pushed
9f8566ee5135: Pushed
alpine: digest: sha256:5aadb68304a38a8e2719605e4e180413f390cd6647602bee9bdedd59753c3590 size: 1154

That’s it, my image is now in the GitLab docker registry. I can check it on the “Registry” page:

 

Cool, now I can run it:

docker run -it  -p 80:80 registry.gitlab.com/mike49/cool-website/nginx:alpine

and test it in the browser at http://localhost . If everything works like expected, you can now deploy it to sloppy.io.

Every new project in GitLab is set to private as default so if you want to make your image public available you have to change the setting for “Project Visibility” in Settings=>General:

 

Now create a new project using the sloppy.io UI and put the GitLab Container Registry uri into the image field. As I tagged the image as alpine, I need to configure that too:

Choose a domain, expose port 80, click deploy project and after a few seconds your container is up and running.

If you need to keep you image password protected, skip the “Project Visibility” part in GitLab and upload the credentials to sloppy.io using the sloppy.io CLI:

sloppy docker-login

Make sure you logged in via docker login registry.gitlab.com which creates an entry for the GitLab Container Registry in /yourhome/.docker/config.json

Are you looking for full managed GitLab server, ready to create docker images of your code and deploy it to sloppy.io? Check sloppy.io – Agile and sign up for a test drive.

Don’t have a sloppy.io account yet? Sign up now, it’s free.