Home > Software > How to Set Up GitLab with Docker Compose: A Comprehensive Guide

How to Set Up GitLab with Docker Compose: A Comprehensive Guide

Anastasios Antoniadis

Discover the seamless process of setting up GitLab with Docker Compose through our comprehensive guide.

Docker (1)

GitLab is a complete DevOps platform that provides a range of software development tools, from project planning and source code management to CI/CD, monitoring, and security. Deploying GitLab using Docker Compose can simplify the setup and maintenance processes, making it an attractive option for teams looking to streamline their development workflow. This guide will walk you through deploying GitLab CE (Community Edition) using Docker Compose.

Prerequisites

Before you begin, ensure you have the following:

  • Docker and Docker Compose installed on your system.
  • A domain or subdomain pointing to your Docker host if you plan to access GitLab over the internet.
  • Basic knowledge of Docker and Docker Compose.

Step 1: Create a Docker Compose File

Create a new directory for your GitLab project. This directory will contain your Docker Compose file (docker-compose.yml) and any additional configuration files.

mkdir gitlab-docker && cd gitlab-docker

Create the docker-compose.yml file:

touch docker-compose.yml

Open the file in your preferred text editor and paste the following configuration:

version: '3.6'

services:
  gitlab:
    image: 'gitlab/gitlab-ce:latest'
    container_name: gitlab
    restart: always
    hostname: 'gitlab.example.com'
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'https://gitlab.example.com'
        # Add any other GitLab configuration here, see https://docs.gitlab.com/omnibus/settings/configuration.html
    ports:
      - '80:80'
      - '443:443'
      - '22:22'
    volumes:
      - './config:/etc/gitlab'
      - './logs:/var/log/gitlab'
      - './data:/var/opt/gitlab'

volumes:
  config:
  logs:
  data:

Replace gitlab.example.com with your domain or subdomain. This configuration mounts three volumes to persist GitLab data, configuration, and logs. It also exposes the standard web (80, 443) and SSH (22) ports.

Step 2: Initialize GitLab

Navigate to your project directory and start GitLab using Docker Compose:

docker compose up -d

It will take a few minutes to initialize the first time you start GitLab. GitLab will set up the necessary configuration files and databases in the mounted volumes.

Step 3: Access GitLab

Once the initialization process is complete, open a web browser and navigate to your domain (e.g., https://gitlab.example.com). You’ll be directed to the GitLab login page.

The first time you access GitLab, you’ll be asked to set a password for the root user. After setting the password, you can log in as root using the password you just created.

Step 4: Configure GitLab (Optional)

After logging in, you can configure GitLab to suit your needs. Some common configurations include setting up email notifications, integrating CI/CD runners, and configuring backup schedules. Refer to the GitLab documentation for detailed guides on various configurations.

Step 5: Update GitLab

To update GitLab to the latest version in the future, simply pull the latest Docker image and restart the service:

docker compose pull gitlab
docker compose up -d

Conclusion

Deploying GitLab with Docker Compose offers a straightforward method to get a GitLab instance running quickly, with easy configuration, backups, and updates. Whether setting up GitLab for a small team or a large enterprise, Docker Compose simplifies the process, allowing you to focus more on development and less on infrastructure management.

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