Skip to main content

Deploy GitLab CE on Docker Swarm


This short tutorial demonstrates how simple it is to deploy applications, in this case GitLab CE, with a Docker Swarm cluster. It builds on the last one, which deployed a Docker Swarm cluster on DigitalOcean.

GitLab CE can also be installed and run on a bare-metal server as well.

It assumes you have a Docker Swarm cluster running and that you have root access to your nodes.

Prepare Manager Node #

First, GitLab CE requires a decent amount of resources. The GitLab CE documentation states the following as minimum requirements:

  • 1 CPU (up to 100 users)
  • 1GB RAM + 3GB Swap (absolute minimum; GitLab recommends 4GB RAM)

Given that we are also running other services on the nodes, you should beef up (resize) your nodes so that they have enough CPU and memory.

Now that we have powerful enough nodes use ssh to connect to your manager node and (assuming you followed the last tutorial) create directories where we’ll store our GitLab CE files:

# mkdir -p /var/swarm/gitlab/{data,logs,config}

Configure GitLab CE #

Configure GitLab CE by changing the yaml file below (the default will probably be fine, though), making sure matches your domain name:

# vim /var/swarm/gitlab/docker-compose.yml
version: "3.6"
    image: gitlab/gitlab-ce:latest
      - proxy
      - /var/swarm/gitlab/data/:/var/opt/gitlab
      - /var/swarm/gitlab/logs/:/var/log/gitlab
      - /var/swarm/gitlab/config/:/etc/gitlab
      GITLAB_OMNIBUS_CONFIG: "from_file('/omnibus_config.rb')"
      - source: gitlab
        target: /omnibus_config.rb
        - traefik.enable=true
        - traefik.backend=gitlab
        - traefik.backend.loadbalancer.swarm=true
        - traefik.port=80
        - traefik.frontend.headers.SSLRedirect=true
        - traefik.frontend.headers.STSSeconds=315360000
        - traefik.frontend.headers.browserXSSFilter=true
        - traefik.frontend.headers.contentTypeNosniff=true
        - traefik.frontend.headers.forceSTSHeader=true
        - traefik.frontend.headers.STSIncludeSubdomains=true
        - traefik.frontend.headers.STSPreload=true
        - traefik.frontend.headers.frameDeny=true
          - node.role == manager
    image: gitlab/gitlab-runner:alpine
      mode: replicated
      replicas: 4
    file: ./gitlab.rb
    external: true

Once that is done, create a configuration file for GitLab CE (replace with your domain name):

# vim /var/swarm/gitlab/gitlab.rb
external_url ''
nginx['listen_port'] = 80
nginx['listen_https'] = false
letsencrypt['enable'] = false

The settings will disable HTTPS and Let’s Encrypt in our GitLab CE instance since we should already have certificates from our Traefik reverse proxy. If you’re not following this tutorial, you must configure GitLab to match your settings.

For more configuration options, refer to the GitLab CE documentation.

Deploy GitLab CE #

# docker stack deploy gitlab --compose-file /var/swarm/gitlab/docker-compose.yml

It’ll take a while, up to a few minutes, until GitLab and the GitLab runners are up. Once up, visit using your browser, and you should be greeted with a page like this:

GitLab Community Edition

Open source software to collaborate on code

Manage Git repositories with fine-grained access controls that keep your code secure. Perform code reviews and enhance collaboration with merge requests. Each project can also have an issue tracker and a wiki.

Last Words #

You should now have a DevOps platform running on top of your Docker Swarm cluster! 😀 If you’d like to know more about GitLab, Git, Docker, and Docker Swarm, here are some book recommendations:

Audible has many books on these topics and others. If you sign up using this link , you’ll get 30 days for free!

Best of luck with GitLab and your Docker Swarm cluster! 😊

Revision #

2023-08-31 Revised language