DEV Community

Frederick Ollinger
Frederick Ollinger

Posted on • Edited on

Update Gitlab On Prem Server Running in a Docker Container

Problem: We had a Gitlab server with repos in it that needed to be updated which was running on prem inside a Docker container. Worse, the container is not versioned. If we restarted the Docker container for any reason, we would wind up with the latest version being run which is not the one which was run when the container was set up. This means losing all our work.

In this example, it's going to be assumed that one all ready has an instance of Gitlab server running in an official container using Docker and that one can start, stop, and connect to the running container.

Surprisingly, that while there is online guides on how to host Gitlab on prem in a Docker container, and there's an official Gitlab Docker container on Docker Hub, there were no instructions on how to update Gitlab inside a Docker container.

How to actually run Gitlab in a Docker container, is beyond the scope of this article.

NOTE: One caveat is that you can NOT make a backup on one version then restore it to another version. In this guide, we suggest backing up twice. 1st before one updates then after an update. That way if things go badly with the update, you still have your original repos in the original backup.

Solution.

1st Step is to backup the container in place so if things go badly, we can restore it:

1st we need to connect to the container:

docker exec -it $CONTAINER /bin/bash
Enter fullscreen mode Exit fullscreen mode

Then backup:

mkdir -p /var/opt/gitlab/backups
/usr/bin/gitlab-backup create force=yes GZIP_RSYNCABLE=yes STRATEGY=copy CRON=1
cp /etc/gitlab/gitlab-secrets.json /var/opt/gitlab/backups
cp /etc/gitlab/gitlab.rb /var/opt/gitlab/backups
Enter fullscreen mode Exit fullscreen mode

Update Gitlab:

In this example, we'll use 14.9.1, but you should pick the version that's right for you via an upgrade path. More information on this is here:

https://docs.gitlab.com/ee/update/index.html#upgrade-paths

apt update
apt install -y curl ca-certificates openssh-server apt-utils perl
curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | bash
apt update
apt install gitlab-ee=14.9.5-ee.0
Enter fullscreen mode Exit fullscreen mode

Now backup again as per the steps above.

Finally, change the tag on the container. In this case, the tag should be 14.9.5-ee. then restart the Docker container.

Finally, restore the latest back which matches the new version:

BACKUPDIR=/home/git/data/backups
cd $BACKUPDIR
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
cp ${BACKUPDIR}/gitlab-secrets.json /etc/gitlab
cp ${BACKUPDIR}/gitlab.rb /etc/gitlab
GITLAB_ASSUME_YES=1 /usr/bin/gitlab-backup restore BACKUP=${BACKUPFILE}
/usr/bin/gitlab-ctl restart
Enter fullscreen mode Exit fullscreen mode

You should be able to go to your Gitlab web page and find that latest version is running and that all your repos are restored.

Top comments (0)