Home / How To / How to install GitLab with Docker on Ubuntu 20.04 LTS

How to install GitLab with Docker on Ubuntu 20.04 LTS



GitLab is an open source storage manager based on Rails developed by GitLab Inc. It is a web based git repository manager that allows your team to collaborate on coding, testing and distribution of applications. GitLab provides several features, including wikis, problem tracking, code reviews, and activity feeds.

In this tutorial we will show you how to install GitLab using Docker and Docker Compose. We will also use Ubuntu 20.04 as our primary operating system and install dockers from the official archive of Ubuntu FocalFossa.

Prerequisites

  • Ubuntu Server 20.04
  • Min 4 GB RAM
  • Root privileges

What should we do?

  • Installing Docker and Docker Compose
  • Setting up the GitLab Docker Project
  • Building a GitLab Container
  • GitLab Post Installation

Step 1 – Installing the Docker and Docker Compose

First, we will install the package dock and docker compose for our Ubuntu 20.04 system. And we will use the dock packages provided by the official Ubuntu FocalFossa repository.

Update all repositories to the latest version and install docker and docker-compose using the apt command below.

  sudo apt update 
sudo apt install docker.io containerd docker-compose

When all installation is complete, start the dock service and add it to the system boot.

  systemctl start docker 
systemctl enable docker

Next, check the docker service using the systemctl command below.

  systemctl status docker 

As a result, the docking service is running on Ubuntu 20.04 Server.

 Install Docker on Ubuntu 20.04

To verify the Docker installation, run the "hello-world" command below.

  docker run hello-world 

Now you get the "hello-world" message from dockers as below.

 Docker runs hello world

Now we are ready to install GitLab with docker container and docker compose.

Step 2 – Setup GitLab Directory

In this step we will set up our project directory for the GitLab installation.

Create a new directory called & # 39; gitlab & # 39; and go into it.

  mkdir -p gitlab; cd gitlab / 

The "gitlab" directory will be used to store all docker scripts and GitLab configuration.

Creating a GitLab Data Directory and .env File

In this section we create a new directory to store all our GitLab data and create a new ".env" file that will be used by docker.

Create a new GitLab data directory "/ srv / gitlab" using the mkdir command below.

  mkdir -p / srv / gitlab / {config / ssl, logs, data} 

Then create a new ".env" file in the "gitlab" project directory with the vim editor.

  vim .env 

Define the environment variable "GITLAB_HOME" with the value as GitLab data directory "/ srv / gitlab" as below.

  GITLAB_HOME = / srv / gitlab 

Save and close.

The script docker-compose.yml will use the environment variable for Gitlab volumes.

Create docker-compose.yml Script

Then we create a new "d docer-compose.yml" which will be used to build our GitLab container.

Create the new & # 39; docker-compose.yml & # 39; file with the vim command below.

  vim docker-compose.yml [19659016] Define the service with the name "web" with the image of "gitlab-ce" latest version and change "hostname" with your GitLab domain name. 

  web: 
image: & # 39; gitlab / gitlab-ce: latest & # 39;
restart: always
hostname: & # 39; gitlab.hakase-labs.io & # 39;

Configure the environment for your Gitlab installation as shown below. And be sure to change "extern_url" with the HTTPS security protocol and change "gitlab_rails ['gitlab_shell_ssh_port']" with your alternate SSH port for the container.

  environment: 
GITLAB_OMNIBUS_CONFIG: |
# Add another gitlab.rb configuration here, each on its own line
extern_url & # 39; https: //gitlab.hakase-labs.io'
gitlab_rails ['gitlab_shell_ssh_port'] = 2224
nginx ['redirect_http_to_https'] = true
nginx ['ssl_certificate'] = "/etc/gitlab/ssl/fullchain.pem"strong19459023] nginx ['ssl_certificate_key'] =" / etc / gitlab /ssl/privkey.pem "
nginx ['ssl_dhparam'] =" /etc/gitlab/ssl/dhparams.pem"ebrit19659016achteNext, define ports for the GitLab container as below. And be sure to replace SSH port "2224" with your custom port and match with "gitlab_shell_ssh_port" port on top.

  ports: 
- & # 39; 80: 80 & # 39;
- & # 39; 443: 443 & # 39;
- & # 39; 2224: 22 & # 39;

Then define the volume or your GitLab data directories. All GitLab data directories are available in the "GITLAB_HOME" directory, which is set to the environment variable of the ".env" file at the top.

  volume: 
- & # 39; $ {GITLAB_HOME} / config: / etc / gitlab & # 39;
- & # 39; $ {GITLAB_HOME} / logs: / var / log / gitlab & # 39;
- & # 39; $ {GITLAB_HOME} / data: / var / opt / gitlab & # 39;
- & # 39; $ {GITLAB_HOME} / config / ssl: / etc / gitlab / ssl & # 39;

Save and close.

Below is the complete configuration.

  web: 
image: & # 39; gitlab / gitlab-ce: latest & # 39;
reboot: always
hostname: & # 39; gitlab.hakase-labs.io & # 39;

environment:
GITLAB_OMNIBUS_CONFIG: |
# Add any other gitlab.rb configuration here, each in its own row
extern_url & # 39; https: //gitlab.hakase-labs.io'
gitlab_rails ['gitlab_shell_ssh_port'] = 2224
nginx ['redirect_http_to_https'] = true
nginx ['ssl_certificate'] = "/etc/gitlab/ssl/fullchain.pem"isie19459023] nginx ['ssl_certificate_key'] =" / etc / gitlab /ssl/privkey.pem"ebrit19459023] nginx ['ssl_dhparam'] = "/ etc / gitlab /ssl/dhparams.pem"

ports:
- & # 39; 80: 80 & # 39;
- & # 39; 443: 443 & # 39;
- & # 39; 2224: 22 & # 39; [19659014] volume:
- & # 39; $ {GITLAB_HOME} / config: / etc / gitlab & # 39;
- & # 39; $ {GITLAB_HOME} / logs: / var / log / gitlab & # 39;
- & # 39; $ {GITLAB_HOME} / data: / var / opt / gitlab & # 39;
- & # 39; $ {GITLAB_HOME} / config / ssl: / etc / gitlab / ssl & # 39;

As a result, the "docker-compose.yml" script for the GitLab project installation has been created.

Generating SSL and DHAPARAM Certificates

In this step, we generate SSL Letsencrypt for our GitLab installation.

On your server, install the certbot tool using the apt command below.

  sudo apt install certbot 

Then generate the SSL certificate for GitLab using the certbot command below.

  certbot certonly --rsa-key-size 2048 - standalone --agree-tos --no-eff-email - email [email protected] -d gitlab.hakase-labs.io 

When everything is ready, your certificates will be available in the & # 39; /etc/letsencrypt/live/gitlab.yourdomain'

Now copy the certificate file "fullchain.pem" and "privkey.pem" to the directory "/ srv / gitlab / config / ssl /".

  cp /etc/letsencrypt/live/gitlab.hakase-labs.io/fullchain.pem / srv / gitlab / config / ssl / 
cp /etc/letsencrypt/live/gitlab.hakase-labs.io/ privkey.pem / srv / gitlab / config / ssl /

And SSL Letsencrypt for GitLab is ready.

Then generate the DHPARAM certificate "dhparam.pem" using the openssl command below.

  sudo openssl dhparam -out /srv/gitlab/config/ssl/dhparams.pem 2048 

And all GitLab installation certificates have been generated, and we are ready to build the GitLab container.

 Setup SSL for GitLab

Step 3 - Build the GitLab container

In this step we will build our GitLab container with all the configuration we have created on top and with the docker-compose command.

Before proceeding, you can check all the available files in the "gitlab" project directory and the directory structure in the GitLab Data directory. [19659017] ls -lah ~ / gitlab /
tree / srv / gitlab

Below is the result you will get.

 Set all files for GitLab Container

Next, go to the project directory "~ / gitlab" and build the GitLab container with the "docker-compose" command below.

  cd ~ / gitlab 
docker-compose up -d

When all is done, you will get the result as below.

 Build Docker Container for GitLab

Now check the drive ports and "LIST" ports on your Ubuntu system with the following command.

  docker-compose ps 
ss -plnt

And you get the container " gitlab_web_1 " is running, and you have the HTTP, HTTPS and SSH port "2224" used by The GitLab container.

 Checking the GitLab Container

As can be seen, the GitLab container is up and running and we are ready to install our GitLab installation.

Step 4 - GitLab Post Installation

Open your browser and type your GitLab URL installation in the address bar.

https://gitlab.hakase-labs.io/

And you will get the reset password for GitLab. [19659014]   GitLab Change password

Enter your new password for the default user "root" and click on the "Change your password" button.

Now you get the GitLab login page as below.

 Gitlab login page as default root user

Log in with the default user " root " and your new password, then click "Login". [19659014] And you will get GitLab Dashboard as below.

 GitLab Dashboard

As can be seen, the GitLab installation with docker and docker compose has been completed.

Step 5 - Basic Configuration GitLab Container

After the GitLab installation, you can add some additional configuration to the GitLab container without destroying t he GitLab container. For this step, we will show you the basic way to handle the GitLab container.

Before proceeding, go to the project directory "~ / gitlab" and check the container status with the following command.

  cd ~ / gitlab 
docker-compose ps

You will get the GitLab container running.

Checking the GitLab service status in the container

To check all GitLab services in the Gitlab container, use the "docker exec" command as below.

  sudo docker exec -it gitlab_web_1 gitlab-ctl status 

Below is the result you will get.

 Gitlab container check services status

As can be seen, all GitLab service components are running.

Access GitLab Container

For SSH to the GitLab container, use "docker exec" with "bash" shell inside the container as below.

  sudo docker exec -it gitlab_web_1 / bin / bash [19659016] Now check the default Ubuntu version of the GitLab container. 

  cat / etc / lsb-release 

You will get the GitLab container based on an Ubuntu 16.04 Xenial.

 Log in to GitLab Container

Now type " exit " to log out of the GitLab container.

Editing the GitLab configuration gitlab.rb

You can then change the GitLab configuration in the container using the default editor on the dock container itself.

Edit the "/etc/gitlab/gitlab.rb" configuration in the container using the docker command below.

  sudo docker exec -it gitlab_web_1 editor / etc / gitlab / gitlab.rb 

Now you get the default "nano" editor on the screen with the configuration file "gitlab.rb".

Write your configuration, save and exit.

Next, to apply the new changes to GitLab, restart the Gitlab container service with the command below.

  sudo docker restart gitlab_web_1 

Now m make sure there is no error, check the status of the GitLab container with the following command.

  sudo docker-compose ps 

Now check that the GitLab cotainer is in " Up (healty) ".

 Configure GitLab Container

As a result, the new configuration for GitLab has been applied.

And finally, the installation of GitLab with docker and docker-compose has been completed successfully.


Source link