Installing GitLab CE with Docker and Docker Compose: A Step-by-Step Guide

If you’ve ever been curious about setting up a GitLab Community Edition (CE) server with Docker and Docker Compose, you’re in the right place. This guide will walk you through every step needed to create an efficient, ready-to-use GitLab environment. But first, let’s take a step back: what makes GitLab and Docker such a winning combination?

Why GitLab and Docker?

GitLab CE is much more than a simple source code management platform: it offers advanced features such as CI/CD pipelines, issue management and Git repositories. The Community Edition, free and open source, is ideal for anyone who wants complete control over their projects without additional costs.

Add Docker and Docker Compose to the equation and you get a modular, easily replicable and simple-to-maintain setup. That’s why this combination is one of the most popular among developers and DevOps teams.

What you need to get started

  • Docker and Docker Compose: if you don’t have them, install with:sudo apt update && sudo apt install docker.io docker-compose -y
  • A server with at least 4 GB of RAM and sufficient space to store repositories and logs.
  • Administrator permissions to manage files and containers.

Creating the base: directory structure

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

The core: docker-compose.yml

nano /srv/gitlab/docker-compose.yml

Insert the following content:

version: '3.8'

services:
  gitlab:
    image: gitlab/gitlab-ce:latest
    container_name: gitlab
    restart: always
    hostname: 'gitlab.example.com'
    ports:
      - '80:80'
      - '443:443'
      - '22:22'
    volumes:
      - /srv/gitlab/config:/etc/gitlab
      - /srv/gitlab/logs:/var/log/gitlab
      - /srv/gitlab/data:/var/opt/gitlab
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'http://gitlab.example.com' # Replace with your domain or IP

Setting permissions

sudo chown -R 1000:1000 /srv/gitlab

Starting GitLab

cd /srv/gitlab
sudo docker-compose up -d

In a few minutes your GitLab server will be up and running. Access it via browser at http://<server_IP> or http://gitlab.example.com. On first login, you’ll be prompted to set the administrator password for the root user.

HTTPS: enabling security

  1. Obtain an SSL certificate (e.g. with Let’s Encrypt).
  2. Update docker-compose.yml, changing the external_url variable:external_url 'https://gitlab.example.com'
  3. Place SSL certificates in /srv/gitlab/config/ssl/.

Useful container management commands

  • Start: sudo docker-compose up -d
  • Stop: sudo docker-compose down
  • View logs: sudo docker-compose logs -f
  • Update GitLab: sudo docker-compose pull && sudo docker-compose up -d

Now it’s your turn

With this guide you have everything you need to set up a GitLab CE server using Docker and Docker Compose. You’ll have a robust, scalable system that can be easily expanded to meet your team’s needs.