Guideschevron_rightServers

Servers · 10 min read · Updated

How to Self-Host GitLab with Docker

To self-host GitLab, run the official gitlab/gitlab-ce Docker image with Docker Compose on a server with enough memory: GitLab gives 16 GB and 8 vCPUs as the baseline for one server, and at least 8 GB for a memory-constrained setup. Set external_url to your https address so GitLab fetches its own certificate, move Git over SSH to its own port, read the first root password from the container, and back up both the data and the secrets file.

Which Server Size for GitLab

Our plans with at least 8 GB, against GitLab's figures. VPS vCPUs are shared threads of the host processor; GitLab advises against burstable instances, so for a busy team a dedicated server, whose cores are all yours, is the steadier choice.

Server plans compared with GitLab's requirements
PlanMemoryCoresFor GitLabPrice
Silver VPS8 GB4 vCPUsMemory-constrained setup$46.50/mo
Gold VPS12 GB6 vCPUsMemory-constrained setup$60.00/mo
Diamond VPS16 GB8 vCPUsMeets GitLab's baseline$73.50/mo
Platinum VPS24 GB12 vCPUsMeets GitLab's baseline$100.00/mo
AMD Ryzen 9 5950X dedicated128 GB16 coresMeets GitLab's baseline$399.00/mo

GitLab also asks for at least 40 GB of disk for the application, plus room for every repository, on SSD storage.

1. Prepare the Server

On Ubuntu 24.04, secure the server and install Docker. Point gitlab.example.com at it and allow ports 80, 443 and 2424 in the firewall. Port 22 stays with the server's own SSH.

sudo mkdir -p /srv/gitlab
export GITLAB_HOME=/srv/gitlab

2. Write the Compose File

In /srv/gitlab/compose.yaml. Replace VERSION with a current release from GitLab's tags (GitLab advises pinning a version rather than using latest in production):

services:
  gitlab:
    image: gitlab/gitlab-ce:VERSION-ce.0
    container_name: gitlab
    restart: always
    hostname: gitlab.example.com
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'https://gitlab.example.com'
        gitlab_rails['gitlab_shell_ssh_port'] = 2424
    ports:
      - "80:80"
      - "443:443"
      - "2424:22"
    volumes:
      - /srv/gitlab/config:/etc/gitlab
      - /srv/gitlab/logs:/var/log/gitlab
      - /srv/gitlab/data:/var/opt/gitlab
    shm_size: "256m"
cd /srv/gitlab
sudo docker compose up -d
sudo docker compose logs -f gitlab     # the first start takes several minutes

With an https external_url and ports 80 and 443 reachable, GitLab requests a Let's Encrypt certificate for itself during the first start.

3. Sign In as Root

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

Sign in at https://gitlab.example.com as root with that password and change it straight away: the file is deleted on the first container restart after 24 hours. Then, under Admin → Settings → General → Sign-up restrictions, turn off sign-ups unless the server is meant to be public.

4. Push Over SSH

Add your SSH key under your profile's SSH Keys, then clone with the port in the address:

git clone ssh://[email protected]:2424/group/project.git

GitLab shows the same address on each project page, because gitlab_shell_ssh_port tells it the port.

5. Back It Up

sudo docker exec -t gitlab gitlab-backup create
# archives land in /srv/gitlab/data/backups

# the backup does not include these; copy them separately and keep them safe
sudo cp /srv/gitlab/config/gitlab-secrets.json /srv/gitlab/config/gitlab.rb /root/

Without gitlab-secrets.json, a restore loses two-factor settings and encrypted CI variables. Send the archives and both files off the server, to a storage box or object storage, from a nightly timer.

CI Runners

GitLab CI jobs run on GitLab Runner, a separate program. Run it on a second server so builds never compete with GitLab for memory, and register it with a token from the project or Admin → CI/CD → Runners page. As with a self-hosted GitHub runner, a runner that can start Docker containers is effectively root on its server, so keep it to code you trust. Want something much lighter than GitLab? Forgejo runs on the smallest VPS.

Common Questions

  • How much RAM does GitLab need?

    GitLab's requirements give 16 GB of memory and 8 vCPUs as the baseline for a single server, and say it can run with at least 8 GB in a memory-constrained setup. Smaller still is possible for a few developers with GitLab's memory-constrained settings, but expect it to be slow.

  • Community Edition or Enterprise Edition?

    The Community Edition (gitlab/gitlab-ce) is free and open source. The Enterprise Edition image runs the same features without a licence and unlocks paid tiers when you add one. For a team that will never buy a licence, CE is the simpler choice.

  • Is GitLab or Forgejo better for a small team?

    GitLab does far more out of the box (CI, registry, planning, security scanning) and needs a much larger server. Forgejo covers repositories, pull requests, issues and Actions on a fraction of the memory. Pick GitLab when you need its features or already use it.

  • Should GitLab use swap?

    GitLab advises disabling swap where possible and giving the server enough memory that it never needs it. On a memory-constrained setup it suggests at least 1 GB of swap as a safety net.

Plans and prices

VPS Plans

Bare-metal servers with the memory and cores to run GitLab and its CI runners side by side.

See all plans
  • Bronze

    3 vCPU · 6 GB RAM · 75 GB NVMe

    2 TB transfer

    $37.50/mo

    Configure inAshburnDallas
  • Silver

    4 vCPU · 8 GB RAM · 100 GB NVMe

    4 TB transfer

    $46.50/mo

    Configure inAshburnDallas
  • Gold

    6 vCPU · 12 GB RAM · 150 GB NVMe

    6 TB transfer

    $60.00/mo

    Configure inAshburnDallas
  • Diamond

    8 vCPU · 16 GB RAM · 200 GB NVMe

    8 TB transfer

    $73.50/mo

    Configure inAshburnDallas

Network port: 10 Gbps in Ashburn, VA, 50 Gbps in Dallas, TX. Pick the location when you configure.

See dedicated servers

Keep Reading

All guides