GitLab docker on Ubuntu

Today I decided to move my self-hosted gitlab instance to Docker so that I will not need to reinstall and configure lots of things when migrating from one host to another host. So I blog this entry to note steps to install gitlab docker on Ubuntu.

Install Docker CE (or Docker Compose if you want)

  1. Simply install Docker-CE:
  2. OR we can download and use docker-compose:

     

Run GitLab with Docker-CE

  1. Init and run the gitlab docker image:
  2. Enter the docker container (with docker exec -ti gitlab bash) to see if configuration is correct to re-run gitlab-ctl reconfigure. You will need to check the external_url variable in /etc/gitlab/gitlab.rb.
  3. Backup your current gitlab, and then transfer to current host server. Remember that in the previous step, we set /var/opt/gitlab in the gitlab container mounted to /srv/gitlab/data in the host machine. So we copy the backup file to /srv/gitlab/data/backups/ and restore the backup:
  4. Do final check on your new gitlab before pointing your DNS to the new IP.
  5. Setup backup with cron on the host machine: 0 0 * * * docker exec -t gitlab gitlab-rake gitlab:backup:create
  6. Setup Let’s Encrypt: we will request certs from host machine and change the gitlab.rb in gitlab container to point to the certs.
    1. Install certbot:
    2. Request for certifications from host machine (we will need to stop docker container since it binds to the port 80):
    3. With the above commands, certs will be stored at /etc/letsencrypt/live/vngit.com/ of the host machine. We will copy certs to gitlab data folder to use it inside gitlab container:
    4. Change /srv/gitlab/config/gitlab.rb to reflect these certs. Add the following nginx lines and change external_url inside it:
    5. Reconfigure gitlab:
    6. Setup cron to renew certs on monthly basis (create a /root/cron-gitlab-certbot-renewal):

Upgrade GitLab to latest version

  1. Remove container, pull the latest image and run it again:

 Backup Docker container to store remotely

  1. First, get the container ID with docker ps command.
  2. To backup a container CONTAINER_ID, user docker commit as follows (we can use either CONTAINER_ID or CONTAINER_NAME. I use name as gitlab instead):

    After this, the backup is saved as a docker image. We can view with docker images.
  3. Save backup as tar file to rsync to remote backup storage:

Restore Docker container from saved backup

  1. Load the backup saved image:
  2. Start a new container with the loaded image:

    Note that in this case, the base image is gitlab_backup, not gitlab/gitlab-ce:latest. We can simply rsync the /srv/gitlab folder to the new server and then run with the gitlab-ce:latest image.

Leave a Reply