GitLab can be self-hosted quite easy. One way is, to run the server in a docker container, which will be described in this article. Our goal is to run a self-hosted GitLab server on a server with a public IP and domain name with GitLab-Runners for CI / CD.

To start with, we will update our server (in our case Debian 10) and install docker-compose:

Shell

Next, we will configure our docker setup. Our GitLab-Server should be located in /srv/gitlab (for example). Therefore we create this folder and add the file docker-compose.yml

YAML

After creating this file, we can startup the GitLab server. The initial start will take a few minutes since everything is set up and configured:

YAML

You can check the logs with the following command:

YAML

During startup, an HTTPS Certificate is generated via Let’s encrypt. When this is done you can open the corresponding domain in the browser and set up the initial password for the user “root”

Now it’s time to configure the runner!

In the admin section (https://<YOUR DOMAIN FOR THE GITLAB SERVER>/admin/runners) you can see the registration token for the runner.

Open the terminal and execute the following command in the folder /srv/gitlab:

YAML

The first “gitlab-runner” is the container name, which we set in our docker-compose.yml (just in case you chose another name)

In the runner registration process, you have to enter the domain (https://<YOUR DOMAIN FOR THE GITLAB SERVER>), the token from the Admin page, a description and optional tags.

When GitLab runner is able to connect to the GitLab instance, you will be asked to enter the executor. In our case, we’ll choose “docker” and “alpine:latest” as the default Docker image.

After this, you should see that our runner is connected to our GitLab Server in the Runner-Setting page (https://<YOUR DOMAIN FOR THE GITLAB SERVER>/admin/runners).

To make this runner available for all projects in the GitLab instance, you have to go to the runner settings and disable the option “Lock to current projects”.

Now you have your self-hosted GitLab instance with CI / CD capabilities!

Leave a comment

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