Update Gitlab in a Docker Container

PowerADM.com / Linux / Update Gitlab in a Docker Container

In this article, we will look at how to upgrade a Gitlab instance that is deployed in a docker container.

Check the current version of Gitlab through the web interface (click the question in the right corner -> Help). Then check out the Gitlab version update path (https://docs.gitlab.com/ee/update/#upgrade-paths).

For example, you have Gitlab version 13.10.2 installed. To upgrade to 14.6.2, you need to perform a whole chain of consecutive upgrades 13.10.2 -> 13.12.15 -> 14.0.12 -> 14.3.6 => 14.6.2.

gitlab upgrade path

Before you start updating Gitlab, make a backup of all mounted partitions (or a snapshot if you’re using a virtual machine).

Updating GitLab in docker is easy – you just need to remove the old container and deploy the container with the new version of the image. After the end of the migration to the new version, you need to migrate to the next one in the chain. And so on, until you reach the target version of Gitlab.

Stop and remove the current container (also remove the image if you previously installed it with the latest tag).

# docker stop gitlab
# docker rm gitlab
# docker image rm gitlab/gitlab-ce:latest

Now run the Gitlab container with the new version. Use the command you used earlier when deploying the Gitlab image for the first time (change only the image tag):

sudo docker run --detach \
  --log-opt max-size=1g \
  --hostname gitlab.poweradm.com \
  --publish 443:443 --publish 80:80 --publish 22:22 \
  --name gitlab \
  --restart always \
  --volume /data/gitlab/config:/etc/gitlab \
  --volume /data/gitlab/logs:/var/log/gitlab \
  --volume /data/gitlab/data:/var/opt/gitlab \
  --volume /data/gitlab/registry:/var/opt/gitlab/registry \
  --env GITLAB_OMNIBUS_CONFIG="external_url 'https://gitlab.poweradm.com/';" \
  gitlab/gitlab-ee:13.12.15-ee.0

You can also use docker-compose:

version: '3.6'
services:
  web:
    image: 'gitlab/gitlab-ee:13.12.15-ee.0'
    restart: always
    hostname: 'gitlab.poweradm.com'
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'https://gitlab.poweradm.com/'
        # Add any other gitlab.rb configuration here, each on its own line
    ports:
      - '80:80'
      - '443:443'
      - '22:22'
      - '5000:5000'
      - '5001:5001'
      - '5005:5005'
    volumes:
      - '/data/gitlab/config:/etc/gitlab'
      - '/data/gitlab/logs:/var/log/gitlab'
      - '/data/gitlab/data:/var/opt/gitlab'
      - '/data/gitlab/registry/config:/var/opt/gitlab/registry'
    logging:
      options:
        max-size: 1g

Execute the following from the directory with the docker-compose.yml file:

# docker-compose up -d

Wait for the applications to launch and the migration to complete. You can check the container log:

# docker logs -f gitlab

Check your GitLab version.

Starting with version 14, in GitLab you need to perform a number of additional steps when migrating. Their status can be tracked here: _https://gitlab.poweradm.com/admin/background_migrations

After updating the version, check the work of all your CI and push/pool repositories. If everything works, upgrade to the next Gitlab version. The steps are the same, starting with stopping and deleting the current container.

Leave a Reply

Your email address will not be published. Required fields are marked *