Docker builds gitlab-ce and restores the database

Scenario: The original gitlab was installed using the apt that comes with ubuntu. It has been used for more than half a year. Finally, it finally lost its strength on the lightweight server of Alibaba Cloud. It died many times a day, and even the website could not be accessed.

It was decided to migrate gitlab to the intranet and run it on a physical machine.

It just so happens that the way of installing through apt is not easy for cloud deployment. Our group may use k8s in the future, so here we directly use docker to connect to gitlab, which is also for learning and practicing docker, which is also more convenient to manage.

Step 1: Backup

Data is the most important, migration must be very careful, don't lose the code base!

If it is gitlab installed by apt, you can directly use the following command to back up

gitlab-rake gitlab:backup:create

Generally speaking, if gitlab is installed with apt, you can find the generated backup file /var/opt/gitlab/backups/below , save this file, and restore it later. In addition to this backup file, it is also recommended to save two files under data: gitlab.rband gitlab-secrets.json, among them, gitlab.rb may also be under /etc, and I usually configure it under etc.

Step 2: Docker installs gitlab

Install directly using docker-compose:

Create a new folder docker, create a new file docker-compose.yml, edit:

version: '2'
services:
   gitlab:
        image: 'gitlab/gitlab-ce:13.2.2-ce.0'
        restart: unless-stopped
        container_name: 'gitlab'
        hostname: 'w2.iict.cn'
        ports:
            - '81:80'
            - '444:443'
            - '23:22'
        volumes:
            - /docker/gitlab/config:/etc/gitlab
            - /docker/gitlab/data:/var/opt/gitlab
            - /docker/gitlab/logs:/var/log/gitlab

Here, map the directory gitlab in docker to the physical machine outside docker: /docker/gitlab/.

So we need to return the three files backed up in the first step and place them in the corresponding locations under /docker/gitlab/data.

And in order to avoid conflicts, the port in docker is mapped to the physical machine respectively: "+1"

use docker-compose upto run

Step Three: Restore the Database

This step must be started with docker gitlab!

docker exec -it gitlab gitlab-rake gitlab:backup:restore BACKUP=1608272828_2020_12_18_13.2.2 --trace

Here the BACKUP variable is followed by the backup file with the suffix removed

start up

docker-compose up
# 或
docker-compose start

The startup of gitlab is slow, and it is clear to wait for the actual page.

some configuration

All configurations are /docker/gitlab/configunder , mainly the gitlab.rb file, external_url should be configured as the same URL as the access address, reverse proxy, and external network, which will be used when git clone

about upgrade

If you use the latest version directly in gitlab-compose, and this latest version is newer than your backup version, a version mismatch error will be reported. At this time, you should follow the backup version and use the corresponding version of gitlab first.

After all the installation is complete and gitlab is started normally, you can modify the gitlab version under docker-compose to latest. Of course, the version span cannot be too large, and the major versions are not compatible.

Guess you like

Origin blog.csdn.net/u014466109/article/details/111473582