Installing GitLab Using Docker

Installing GitLab Using Docker


GitLab is a robust platform for managing Git repositories, offering a variety of features for development teams to collaborate efficiently. A convenient way to deploy GitLab is through Docker Compose, making it easy to set up and manage the environment.In this tutorial, I will demonstrate the steps required to install GitLab using Docker Compose, allowing you to get your own GitLab server up and running quickly and easily.

Environment#

For this implementation, I am using a Linux server with Ubuntu distribution version 22.04.

The server I used has the following configuration: 2 vCPUs, 4GB RAM and a 30GB SSD disk.

For our server to be accessible via the internet, and for our GitLab to generate the certificate via Let’s Encrypt, we need to have a public IP address and we need to open ports 80 and 443 to the internet.

We also need to have a DNS record to create the URL for GitLab.

I have made Docker Compose available in the following GitHub repository:

alfredotavio/gitlab-docker
null
0
0

Images used:

Structure:

.
└── docker-compose.yml

I will not cover the installation of Docker Engine, if you still do not know how to install it, see this other post:

How to Install Docker Engine on Linux
·572 words·3 minutes
DockerDocker ComposeLinuxUbuntuHundreds

Step 01 – Creating the DNS record#

First of all, let’s define and create the URL that we will use for GitLab.

I will use the domain alfredocastro.com.br, I defined the URL gitlab.alfredocastro.com.br – ATTENTION: You need to change it in the Docker Compose file (docker-compose.yml).

Access your domain’s DNS record manager and create an A record using your server’s public IP address as the value.

Here’s an example:

Thiết kế hệ thống chuyên nghiệp OceanTech-Group 01 Installing GitLab Using Docker Thủ thuật

To check the propagation of the created record, visit the website: WhatsMyDNS

Thiết kế hệ thống chuyên nghiệp OceanTech-Group 02 Installing GitLab Using Docker Thủ thuật

Step 02 – Cloning the Docker Compose repository#

After installing Docker Engine, let’s continue with our implementation.

Thiết kế hệ thống chuyên nghiệp OceanTech-Group 01 Installing GitLab Using Docker Thủ thuật

Run the following commands to clone our Docker Compose into our server:

cd /opt
git clone https://github.com/alfredotavio/gitlab-docker.git
cd gitlab-docker
Thiết kế hệ thống chuyên nghiệp OceanTech-Group 02 Installing GitLab Using Docker Thủ thuật

NOTE: I used the Linux /opt directory, if you want you can change it to another directory of your choice.

Step 03 – Setting the GitLab URL#

First let’s define the access URL, edit the docker-compose.yml file in the project root and change the GitLab URL, there are two lines, in the current project it is set to gitlab.example.com.

vim /opt/gitlab-docker/docker-compose.yml
Thiết kế hệ thống chuyên nghiệp OceanTech-Group 01 Installing GitLab Using Docker Thủ thuật

Step 04 – Running Docker Compose#

To upload our environment, simply run the following command within the root directory where our docker-compose.yml is located:

docker compose up -d
Thiết kế hệ thống chuyên nghiệp OceanTech-Group 01 Installing GitLab Using Docker Thủ thuật

NOTE: Docker will download and provision all images. Wait a few minutes for the images to complete the first-time setup.

Step 05 – Accessing the environment#

By default, GitLab automatically sets a temporary password found inside the “initial_root_password” file. To get the password, use the following command:

docker exec -it gitlab grep "Password:" /etc/gitlab/initial_root_password
Thiết kế hệ thống chuyên nghiệp OceanTech-Group 01 Installing GitLab Using Docker Thủ thuật

Access the GitLab URL that we defined in the first step, you will be asked for a username and password to access, by default the user is “root” and the password will be the one displayed in the previous command.

Thiết kế hệ thống chuyên nghiệp OceanTech-Group 02 Installing GitLab Using Docker Thủ thuật
Thiết kế hệ thống chuyên nghiệp OceanTech-Group 03 Installing GitLab Using Docker Thủ thuật

After performing the first login, it is recommended to change the password and email of the “root” user, it is also recommended to disable the public registration option.

To change the password and email of the “root” user, after logging in, click on the user’s profile picture in the left side tab.

Thiết kế hệ thống chuyên nghiệp OceanTech-Group 04 Installing GitLab Using Docker Thủ thuật

Then click on “Edit profile”.

Thiết kế hệ thống chuyên nghiệp OceanTech-Group 05 Installing GitLab Using Docker Thủ thuật

In the “Profile” tab, scroll down to the “Email” field and change the email “ admin@example.com ” to your email address, then click “Update profile settings”.

Thiết kế hệ thống chuyên nghiệp OceanTech-Group 06 Installing GitLab Using Docker Thủ thuật

You will be asked to confirm the “root” user password, use the temporary password we got earlier.

Thiết kế hệ thống chuyên nghiệp OceanTech-Group 07 Installing GitLab Using Docker Thủ thuật

Now click on the “Password” tab in the left side menu.

Thiết kế hệ thống chuyên nghiệp OceanTech-Group 08 Installing GitLab Using Docker Thủ thuật

In “Current password”, enter the temporary password we got earlier, in “New password” define a new password and in “Password confirmation” repeat the new password, then click on “Save password”.

Thiết kế hệ thống chuyên nghiệp OceanTech-Group 09 Installing GitLab Using Docker Thủ thuật

You will be logged out and a message will appear saying that the password was updated successfully.

Thiết kế hệ thống chuyên nghiệp OceanTech-Group 10 Installing GitLab Using Docker Thủ thuật

Log in again, now using the new password. Let’s disable the public registration option. After logging in, a warning message will be displayed: “Check your sign-up restrictions – Your GitLab instance allows anyone to register for an account, which is a security risk on public-facing GitLab instances. You should deactivate new sign ups if public users aren’t expected to register for an account.” Click the “Deactivate” button.

Thiết kế hệ thống chuyên nghiệp OceanTech-Group 11 Installing GitLab Using Docker Thủ thuật

Uncheck the “Sign-up enabled” option and click the “Save changes” button.

Thiết kế hệ thống chuyên nghiệp OceanTech-Group 12 Installing GitLab Using Docker Thủ thuật

Okay, now we have launched GitLab and made the first security configurations.

Step 06 – Integrating GitLab with GitLab Runner#

To integrate GitLab Runner with GitLab, you must generate a token and register within GitLab Runner.

To generate the token you need to access the “Admin Area”, on the home screen after logging in, click on the “Configure GitLab” box.

Thiết kế hệ thống chuyên nghiệp OceanTech-Group 01 Installing GitLab Using Docker Thủ thuật

In the left side menu, click on “CI/CD” and then on “Runners”.

Thiết kế hệ thống chuyên nghiệp OceanTech-Group 02 Installing GitLab Using Docker Thủ thuật

Click on the “New instance runner” button.

Thiết kế hệ thống chuyên nghiệp OceanTech-Group 03 Installing GitLab Using Docker Thủ thuật

Make the following settings:

In “Platform” select “Linux”.

Under “Tags” check the box “Run untagged jobs”.

Click on the “Create runner” button.

Thiết kế hệ thống chuyên nghiệp OceanTech-Group 04 Installing GitLab Using Docker Thủ thuật
Thiết kế hệ thống chuyên nghiệp OceanTech-Group 05 Installing GitLab Using Docker Thủ thuật

Copy and write down the command displayed in “Step 1” and click the “Go to runners page” button.

Thiết kế hệ thống chuyên nghiệp OceanTech-Group 06 Installing GitLab Using Docker Thủ thuật

See that our Runner is in “Idle” status and the last interaction is “Never”.

Thiết kế hệ thống chuyên nghiệp OceanTech-Group 07 Installing GitLab Using Docker Thủ thuật

Now we must access the terminal where our Docker Compose is located to run the GitLab Runner registration command. Access your Linux instance and type the following command to register the GitLab Runner within your GitLab, remember to change the “–url” and “–token” fields to the information corresponding to your previously generated Runner.

docker exec -it gitlab-runner gitlab-runner register --name MyRunner --url "https://gitlab.alfredocastro.com.br" --token "glrt-FyeL9ZZz6QozSD2aJE3x" --executor docker --docker-image "docker:latest" --non-interactive

The execution should return a message similar to the following print “Runner registered successfully”.

Thiết kế hệ thống chuyên nghiệp OceanTech-Group 08 Installing GitLab Using Docker Thủ thuật

Go back to the browser with the Runners and refresh the page to see the status of our Runner, see in the print that it has the status “Online” and already has the time of the last interaction.

Thiết kế hệ thống chuyên nghiệp OceanTech-Group 09 Installing GitLab Using Docker Thủ thuật

Okay, we’ve now uploaded our environment with GitLab and GitLab Runner integrated.

I hope I’ve helped! If you have any questions, don’t hesitate to contact me.

Tags:

THIẾT KẾ HỆ THỐNG AD - EMAIL - ECOSYSTEM - AUTOMATION INTERGRATION CHUYÊN NGHIỆP - BẢO MẬT

 

Liên hệ ngay với OceanTech-Group để thiết kế hệ thống trơn chu chuẩn bảo mật cho doanh nghiệp của bạn!

Hotline: 0774-751-773
X
Chat với chúng tôi !