Deploy GitLab Through Docker
Table of Contents
About
GitLab is an excellent open source self-hosted alternative to using GitHub. However, I find it to be much more useful and don't really think of it as an "alternative" at all.
Deploying GitLab through Docker has become a lot simpler than it used to be, and this tutorial will show you how in just a few simple steps.
Related Posts
Deployment Instructions
Requirements
- At least 2GB RAM, preferably 3+
Install Docker
If you haven't already, install docker, then install docker compose.
Configure SSH Port
Next, we need to change the server's SSH port from the default 22 to something else such as 2222 or 23825. You can do this by
editing the /etc/ssh/sshd_config
file and changing the line below
...
# What ports, IPs and protocols we listen for
Port 22
...
You will need to remember this so that next time you SSH into the server, you specify the port with -p
like so:
ssh -p 2222 my-host-or-ip.org
Docker Run Command
Now we can deploy the gitlab container by executing the following script:
HOSTNAME="gitlab.mydomain.com"
sudo docker run \
--detach \
--hostname $HOSTNAME \
--publish 443:443 \
--publish 80:80 \
--publish 22:22 \
--publish 5000:5000 \
--publish 5001:5001 \
--name gitlab \
--restart always \
--volume $PWD/gitlab/config:/etc/gitlab \
--volume $PWD/gitlab/logs:/var/log/gitlab \
--volume $PWD/gitlab/data:/var/opt/gitlab \
--log-driver json-file \
--log-opt max-size=10m \
--log-opt max-file=3 \
gitlab/gitlab-ce:latest
http://
or https://
.
Docker Compose File
If you wish to use Docker compose instead, then the equivalent would be:
services:
gitlab:
container_name: "gitlab"
image: gitlab/gitlab-ce:${GITLAB_VERSION}
ports:
- "443:443"
- "80:80"
- "22:22"
- "5000:5000"
- "5001:5001"
restart: always
volumes:
- ./gitlab/config:/etc/gitlab
- ./gitlab/data:/var/opt/gitlab
- ./gitlab/logs:/var/log/gitlab
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
Login - Default User
After the container has deployed, you will need to wait a while before the website will appear when you type your server's IP or hostname into your browser's URL.
To log in, the default user is root
. You will then need to find out what the password is, which can be found by executing the following command on the host:
sudo docker exec -it \
gitlab \
grep 'Password:' /etc/gitlab/initial_root_password
Updating GitLab
If you are updating GitLab frequently (like once a month), then you will generally be updating by just one version at a time, and don't need to worry about issues that can arise if you are jumping multiple versions. In such a case, you can just keep running the following commands to update to the latest version of GitLab. However, I recommend taking a snapshot of your server first just in case.
# Pull the latest image
docker pull gitlab/gitlab-ce:latest
# kill and remove the existing container
docker stop `gitlab`
docker rm `gitlab`
# Launch a new container using the new image.
sudo docker run \
--detach \
--hostname gitlab.example.com \
--publish 443:443 \
--publish 80:80 \
--publish 22:22 \
--publish 5000:5000 \
--publish 5001:5001 \
--name gitlab \
--restart always \
--volume /srv/gitlab/config:/etc/gitlab \
--volume /srv/gitlab/logs:/var/log/gitlab \
--volume /srv/gitlab/data:/var/opt/gitlab \
--log-driver json-file \
--log-opt max-size=10m \
--log-opt max-file=3 \
gitlab/gitlab-ce:latest
Updating Across Multiple Versions
If you are updating across multiple versions, then you need to use a tool like the Gitlab Upgrade Path, to specify your current version and your desired version, for which it will tell you about any intermediary versions you need to update to along the way first.
Once you have those intermediary versions, use the Docker tags to upgrade to those images one by one, and be sure to wait until all of the background migrations have completed each time, before running the next upgrade step.
References
First published: 16th August 2018