Programster's Blog

Tutorials focusing on Linux, programming, and open source

Deploy GitLab Through Docker

Deploying Gitlab through docker has become a lot simpler than it used to be.

Requirements

  • At least 2GB RAM, preferably 3+

Steps

If you haven't already, install docker, then install docker compose.

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

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 \
    --name gitlab \
    --restart always \
    --volume $PWD/gitlab/config:/etc/gitlab \
    --volume $PWD/gitlab/logs:/var/log/gitlab \
    --volume $PWD/gitlab/data:/var/opt/gitlab \
    gitlab/gitlab-ce:latest

Don't forget to set the HOSTNAME.

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.

Updating Gitlab

Run 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 kill `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 \
    --name gitlab \
    --restart always \
    --volume /srv/gitlab/config:/etc/gitlab \
    --volume /srv/gitlab/logs:/var/log/gitlab \
    --volume /srv/gitlab/data:/var/opt/gitlab \
    gitlab/gitlab-ce:latest

References