Setup GitLab CE using Docker
AWS devops Docker

Setup GitLab CE using Docker


When working on new project, i am always prefer to use GitLab as git repository and CICD platform, if there is no gitlab server or we are now allowed to use Gitlab saas, it's time for me to deploy self-managed gitlab ce using docker. The architecture is like this.

In the context of this post i will deploy haproxy and gitlab using docker compose. They will share same docker network and haproxy will expose port 443 (for https) and 24 to the host machine. Haproxy also do tls terminate and forward traffic to gitlab server inside docker.

We will do these following step

  • Prepare SSL cert and key
  • Prepare gitlab.rb configuration
  • Prepare haproxy.cfg configuration
  • Prepare docker-compose.yml configuration
  • Deploy service using docker compose up command.

Prepare SSL cert and key

If you did not own any cert, go grab it after reading this post Haproxy need us to merge cert and key, simply copy the content of two files into one file or executing two commands.

cat tls.crt > tls.pem
cat tls.key >> tls.pem

For me after doing this, i got tls.pem content same as

Prepare gitlab.rb configuraton

Gitlab server need config to initial server, copy the content and editing external_url to your dns. After that map your domain dns record to server public ip. For example i will set A Record for to while is public ip server. You also need to add firewall rule to access ingress to port 443 and 24 .

You also need to update  smtp config, change your gmail password and user, if you use another email server, update to yours. You also need to change  initial_root_password.

external_url  ''
nginx['listen_port'] = 8000
nginx['listen_https'] = false
gitlab_rails['monitoring_whitelist'] = ['']
gitlab_rails['gitlab_shell_ssh_port'] = 24
registry['enable'] = false
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = ""
gitlab_rails['smtp_port'] = 587
gitlab_rails['smtp_user_name'] = "coppernguyen"
gitlab_rails['smtp_password'] = "pleasechangeyourpassword"
gitlab_rails['smtp_domain'] = ""
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = false
prometheus_monitoring['enable'] = false
grafana['enable'] = false
gitlab_rails['pipeline_schedule_worker_cron'] = "* * * * *"
gitlab_rails['initial_root_password'] = "b0f97a668d7119fda65e1d67d09eedbfd1fd4823"

Prepare haproxy.cfg configuration

Haproxy need config to be run, copy the content of this file and write to haproxy.cfg

	maxconn 8192
    ulimit-n 1000000
    log stdout format raw daemon debug

resolvers docker
    nameserver dns1
    hold valid 10s

	log     global
	mode    http
	option  httplog
	option  dontlognull
	option httpchk
    option forwardfor
    http-reuse aggressive
	timeout connect 2s
	timeout client 1m
	timeout server 5s

listen https
	bind *:80
	bind *:443 ssl crt /tls.pem
	redirect scheme https if !{ ssl_fc }
    stats uri /stats
	http-check send meth GET uri /-/health
	http-check expect status 200
	server gitlab gitlab:8000 resolvers docker init-addr none check inter 2s  fall 5  rise 5

listen ssh
	bind *:24
	mode tcp
	option tcplog
    mode tcp
	option tcp-check
	server gitlab gitlab:22 resolvers docker init-addr none check  observe layer4  error-limit 10  on-error mark-down

In this configuration, i define two listen, one for https port and one for ssh port.  They both forward to gitlab server port. Beside that, when we visit /stats via https port we will see our haproxy backend stats.

Prepare docker-compose.yml configuration

The content of compose's file look like this.

version: "3.9"

    name: gitlab
    driver: bridge


    file: ./gitlab.rb
    file: ./haproxy.cfg

  restart: unless-stopped
  mem_limit: 8192m

    <<: *service-common
    image: haproxy:lts-alpine3.17
      - 80:80
      - 443:443
      - 24:24
      - source: haproxy
        target: /usr/local/etc/haproxy/haproxy.cfg
      - ./tls.pem:/tls.pem
    <<: *service-common
    image: 'gitlab/gitlab-ce:latest'
      - source: gitlab
        target: /etc/gitlab/gitlab.rb
      - config:/etc/gitlab
      - logs:/var/log/gitlab
      - data:/var/opt/gitlab

You will see that i create two service, and also two configuration mount into 2 service.Our directory tree look like this so far.

Deploy using docker compose up

Run this command to deploy all service.

docker compose up -d

Go to /stats to view stats, for me i will go to because is my external_url i set on gitlab.rb configuration.

From image above, we see that our gitlab is up, now is time to login. Go to, login with root and initial_root_password you have set in gitlab.rb above.

That is, we deployed gitlab server. Thank for reading the post.