How To Install Gitlab Server With Docker

Author - How to set up a GitLab Server with docker compose
Cristian
May 24th, 2020
How to set up a GitLab Server with docker compose

How to set up a GitLab Server with docker compose

As a programmer, working with a version control system these days is mandatory. There are a few very known solutions for software development version control like GitLab, Github, or BitBucket. 

A very powerful tool is GitLab. From project planning and source code management to CI/CD and monitoring, GitLab is a complete DevOps platform, delivered as a single application. On May 22, a  new version has been released, GitLab 13.0, with Epic Hierarchy on Roadmaps, Auto Deploy to ECS, and much more to help you iterate quickly on a High Availability platform.

You can have GitLab as a hosted service or you can build your own server from scratch. In this article, we will focus on how to set up a private GitLab server using docker-compose.

1. The VPS

First, we need a VPS (virtual private server) or just a server which has access to the internet, but before to pick one let’s have a look at GitLab Requirements page here docs.gitlab.com

For my GitLab server, I bought a VPS from ovh.co.uk with minimal requirements, 1 core, 4GB RAM, and 4GB swap. There are other options for a VPS like digitalocean.com for example, but this a subject for a different article.

The next step is to decide the operating system you would like to run on this VPS. There are plenty of options there, and I will pick a Linux CentOS distro because I find it easy to manage.

2. Docker-compose settings

The code source can be found here: github.com

Let’s explore a bit the docker-compose settings.

web:
  image: 'gitlab/gitlab-ee:latest'
  restart: always
  hostname: 'hostname'
  container_name: 'gitlab-web'

The hostname is the domain name or the subdomain name set in your DNS server. It is very important it exists and pointed to the IP of your VPS because GitLab has integrated an auto-SSL installation based on Le’s Encrypt and if the hostname does not exist the process will fail and your system might not work as you expected.

environment:
    GITLAB_OMNIBUS_CONFIG: |
      external_url 'https://hostname/'
      gitlab_rails['lfs_enabled'] = true

I do recommend to set LFS Enabled = true. There will be cases like visual tests for example when the screenshots taken by the tests will use lots of storage resources so maybe you will want to push only the bit has been changed not the entire image.
For more details about git LFS please have a look here  about.gitlab.com 

ports:
    - '80:80'
    - '443:443'
    - '22222:22'

I will map port 22222 to 22 of the GitLab container only because I need access to my VPS SSH server. Of course, you can change the SSH port in the VPS server from 22 to 10000 let’s say, and after that, you can map 22 to 22, but this is again a subject for a different article.

 volumes:
    - '/srv/gitlab/config:/etc/gitlab'
    - '/srv/gitlab/logs:/var/log/gitlab'
    - '/srv/gitlab/data:/var/opt/gitlab'

I have created the folder 'srv/gitlab' on my VPS where I mount the GitLab config folder, the data, and the logs ones. In the config folder, you should have an SSL sub-folder where you can put your own SSL certificate if Let’s encrypt is not a solution you like.

3. Starting the GitLab Server

Using the terminal, you have to navigate to the folder you have the .docker-compose.yml file and run the command:

docker-compose up -d

It will take a couple of minutes until the GitLab Server will be completely installed. You can watch the progress in the terminal if you use to watch the container logs with:

docker logs -f gitlab

That is all! Your server should be up and running!

4. Subscribe

There will be more articles about GitLab like Gitlab pipeline and runners, Gitlab runners with cache and more other interesting subjects, so I please subscribe to get the news. 

Thank you!