GitLab on Docker

Page content

Install GitLab running on Docker

Here is the official document. I followed it.

Caution: I’m using my GitLab on VM, not Docker image. Because the official image doesn’t contain e-mail client, and it is a little bit hard to understand. For me, deploying it on premise or VM is easy.

Install docker

apt install -y docker.io

Set path

export GITLAB_HOME=/srv/gitlab

Configurations and repositories would be stored in this path.

Run a container

sudo docker run --detach \
  --hostname {{ your_hostname }} \
  --publish 443:443 --publish 80:80 --publish 2222:22 \
  --name gitlab \
  --restart always \
  --volume $GITLAB_HOME/config:/etc/gitlab \
  --volume $GITLAB_HOME/logs:/var/log/gitlab \
  --volume $GITLAB_HOME/data:/var/opt/gitlab \
   gitlab/gitlab-ce:latest

I changed git port to 2222 because the server should be access by ssh.

Make as a service

I want to run the container automatically when its boot time.

https://stackoverflow.com/questions/30449313/how-do-i-make-a-docker-container-start-automatically-on-system-boot

systemctl enable docker

Write /etc/systemd/system/gitlab.service as below.

[Unit]
Description=GitLab docker
Requires=docker.service
After=docker.service

[Service]
Restart=always
ExecStart=/usr/bin/docker start -a gitlab
ExecStop=/usr/bin/docker stop -t 2 gitlab

[Install]
WantedBy=default.target
systemctl enable gitlab