How to Setup GitLab Docker Compose Container Image

How to Setup GitLab Docker Compose Container Image. In this post, we introduce GitLab, its advantages then explain how to install GitLab with Docker and Docker Compose.

GitLab is a tool that helps developers manage their code and collaborate with their team. Being a lifecycle tool, Gitlab offers a large store of web based DevOps resources. It uses an open source license to provide issue tracking on CI/CD pipeline features.

The license is granted by GitLab Inc. Valery Sizov created it on several platforms used by tech companies such as IBM, Sony, Cisco, Juniper, Oracle, and others. All in all, GitLab brings teams together. Aids planning all the way to production, so it minimizes cycle times and improves security. All in all, that leads to increased developer productivity.

What is GitLab?

Image Source: YouTube

Above all, GitLab is a web based Git repository manager that provides source code management (SCM), continuous integration, and more. Self hosted, meaning you install it on your server or hosting environment.

Able to access the code from numerous computer languages and generally it is in Ruby and fewer sections are programmed in Go. The code source administration assists the software development process.

Features of GitLab

1. Source code management

Besides, GitLab makes source code management easy. It provides a web based interface for managing Git repositories and collaborating with team members. GitLab provides straightforward code reviews, asset version control, feedback loops, and strong branching patterns to assist your engineers in solving challenges and delivering value.

2. Continuous integration and delivery

Certainly, GitLab include built in support for continuous integration and delivery (CI/CD), allowing developers to automate the build, test, and deployment process. It offers feedback through code reviews, and automates code security and quality testing.

3. Issue tracking and project management

Use GitLab for tracking issues and plan work. GitLab helps you track tasks and work status, accept feature proposals, discuss the implementation of an idea, and elaborate on code implementations.

4. Security and compliance

GitLab include secure code review, access control, and compliance reporting. By continuously scanning weaknesses in source code, containers, dependencies, and running applications, GitLab assists you in moving security to the left. You implement guardrail controls to protect your production system.

5. Customization and extensibility

Concurrently, GitLab is highly customizable and you extend it with a wide range of plugins and integrations. You customize almost everything to from custom build packs, to Dockerfiles, and Helm charts. Also enable staging and canary deployments, manage Auto DevOps with GitLab APIs, and more.

Advantages of GitLab

1. Self hosting

Install GitLab on your server or hosting environment, giving you control over your data and infrastructure.

2. Customization

Highly customizable, allowing you to tailor it to your specific needs and workflow. GitLab includes a wide range of tools for source code management, continuous integration, and project management, all in one place.

3. Community edition

GitLab has a community edition that is free to use and open source, making it an affordable option for small teams and organizations.

4. Security Capabilities

Consequently, GitLab protects that the application’s source codes and resources against any unauthorized or harmful access, use, or distribution. It employs the Kerberos protocol, which requires user authentication before allowing access to a particular network.

5. Support Services

Users seek help with any pertinent issues they may have, such as upgrading to a different GitLab plan or package, using the services supplied by the quick application development solution.

We have come to the main part of the article about how to Setup GitLab Docker Compose Container Image.

How to Setup GitLab Docker Compose Container Image

Prerequisites

  • An Ubuntu 20.04 server installed on your system.
  • A root user or a user with sudo privileges.

Step 1 - Update All System Packages

Before doing anything, it is recommended to update and upgrade all your system packages to the latest version. Update all the packages using the following command.

				
					apt update -y
apt upgrade -y

				
			

After updating all the system packages, you also need to install some additional packages to your server. You install all of them by running the following command.

				
					apt install ca-certificates curl openssh-server apt-transport-https gnupg2 -y
				
			

Once all the required packages are installed, you can proceed to install the Docker and Docker Compose.

Step 2 - Install Docker and Docker Compose

To install the latest Docker version, you need to add the Docker’s official repository to your system. First, download the Docker GPG key with the following command.

				
					curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
				
			

Next, add the Docker official repository to the APT with the following command.

				
					echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
				
			

Then, update the repository cache with the following command.

				
					apt update -y
				
			

Next, install both Docker and Docker Compose package using the following command.

				
					apt install docker-ce docker-compose -y
				
			

After the successful installation, you verify the Docker version with the following command.

				
					docker --version
				
			

You should see the Docker latest version in the following output.

				
					Docker version 20.10.22, build 3a2c30b
				
			

To verify the Docker Compose version, run the following command.

				
					docker-compose --version
				
			

You will see the Docker Compose version in the following output.

				
					docker-compose version 1.29.2, build unknown
				
			

Step 3 - Create a Docker Compose File for GitLab

First, create a directory for your GitLab installation using the following command.

				
					mkdir project
				
			

Next, create a data directory to store GitLab data.

				
					mkdir /data
				
			

Then, export the data directory with the following command.

				
					export GITLAB_HOME=/data
				
			

After that, change the directory to your project and create a docker-compose.yml configuration file for GitLab.

				
					cd project
nano docker-compose.yml
				
			

Add the following configurations.

				
					
version: '3.7'
services:
  web:
    image: 'gitlab/gitlab-ce:latest'
    restart: always
    hostname: 'localhost'
    container_name: gitlab-ce
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'http://localhost'
    ports:
      - '8080:80'
      - '8443:443'
    volumes:
      - '$GITLAB_HOME/config:/etc/gitlab'
      - '$GITLAB_HOME/logs:/var/log/gitlab'
      - '$GITLAB_HOME/data:/var/opt/gitlab'
    networks:
      - gitlab
  gitlab-runner:
    image: gitlab/gitlab-runner:alpine
    container_name: gitlab-runner    
    restart: always
    depends_on:
      - web
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - '$GITLAB_HOME/gitlab-runner:/etc/gitlab-runner'
    networks:
      - gitlab

networks:
  gitlab:
    name: gitlab-network

				
			

Save and close the file when you are finished.

A brief explanation of each option in the above configuration file is shown below.

  • image – Specify the docker image for GitLab that you want to use in our server
  • ports – Define list of ports that make available outside the container. In this post, we use ports 80, 443.
  • container_name – Define the name of the container.
  • volumes – Define the volumes for the container. In this configuration, we have directories shared with our system (subdirectories in $GITLAB_HOME) and an additional volume that allows access to the Docker environment from the GitLab runner.
  • networks – Specify the virtual network for containers. In this case, we will use gitlab-network.
  • localhost – Define the hostname of GitLab container.

Step 4 - Launch GitLab Docker Container

At this point, docker-compose.yml file is ready to create and run GitLab container. You can now run the following command to launch the container.

				
					docker-compose up -d
				
			

This command will download all required images and create container for GitLab and other services.

				
					Creating network "gitlab-network" with the default driver
Pulling web (gitlab/gitlab-ce:latest)...
latest: Pulling from gitlab/gitlab-ce
846c0b181fff: Pull complete
4e9f37801cd6: Pull complete
433d95578d03: Pull complete
d0506f369eef: Pull complete
4b8b41985700: Pull complete
f303beab1337: Pull complete
421107247076: Pull complete
97ebf54f2cd8: Pull complete
Digest: sha256:d9cff32a3b87bd3a7f417e1d0d09753a5fd8c586656e4f85dd949d547298eb82
Status: Downloaded newer image for gitlab/gitlab-ce:latest
Pulling gitlab-runner (gitlab/gitlab-runner:alpine)...
alpine: Pulling from gitlab/gitlab-runner
9621f1afde84: Pull complete
fc777c8f525f: Pull complete
64596e3b14f8: Pull complete
Digest: sha256:786dbb4b65fde886ebaac69ad0c2b2ab372155ca7ba2364fb384bd4a481521b4
Status: Downloaded newer image for gitlab/gitlab-runner:alpine
Creating gitlab-ce ... done
Creating gitlab-runner ... done

				
			

Now verify all running container using the following command.

				
					docker-compose ps
				
			

You will get the status of all containers in the following output.

				
					    Name                   Command                       State                                           Ports                                
----------------------------------------------------------------------------------------------------------------------------------------------
gitlab-ce       /assets/wrapper                  Up (health: starting)   22/tcp, 0.0.0.0:8443->443/tcp,:::8443->443/tcp,                      
                                                                         0.0.0.0:8080->80/tcp,:::8080->80/tcp                                 
gitlab-runner   /usr/bin/dumb-init /entryp ...   Up                                                                                           

				
			

At this point, the GitLab container is started and listens on port 80. You now proceed to the next step.

Step 5 - Access GitLab Web Interface

Before accessing the GitLab web interface, you are required an admin password to login to the GitLab dashboard. You retrieve the GitLab login password with the following command.

				
					docker exec -it gitlab-ce grep 'Password:' /etc/gitlab/initial_root_password
				
			

You should get the root password in the following output.

				
					Password: v+UWPHyW4hkOBfWt6bdU6iwZaGLV6hnGb6f+CzEIvQU=

				
			

Now, open your web browser and access the GitLab web interface using the URL http://your-server-ip. You will be redirected to the GitLab login page.

Provide your username, password and click on the Sign in button. Once you are logged in, you are redirected to the GitLab dashboard as shown below.

If you have any trouble accessing the GitLab, you check the GitLab log using the following command.

				
					docker logs gitlab-ce
				
			

To shutdown all running containers, run the following command.

				
					docker-compose down
				
			

Thank you for reading How to Setup GitLab Docker Compose Container Image. We shall conclude this article now.

How to Setup GitLab Docker Compose Container Image Conclusion

In this guide, we showed you how to install GitLab with Docker and Docker Compose on Ubuntu. You can now start creating your first GitLab project to test your code. GitLab is a powerful and versatile tool for managing and collaborating on code projects. Its features, such as version control, project management, and continuous integration, make it an essential tool for any software development team. Additionally, its open source nature and extensive documentation make it a great choice for individuals and organizations looking to streamline their development process. Overall, GitLab is a valuable tool that greatly improve the efficiency and productivity of any code project.

Do explore more of our Gitlab content by navigating to our blog over here

Avatar for Hitesh Jethva
Hitesh Jethva

I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x