Gitlab Docker Installation with Backup & Restore - lyonwang/TechNotes GitHub Wiki
Install docker on Centos 7
Step 1 — Install Docker
$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2
Configure the docker-ce repo:
$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Install docker-ce:
$ sudo yum install docker-ce
Set Docker to start automatically at boot time:
$ sudo systemctl enable docker.service
Finally, start the Docker service:
$ sudo systemctl start docker.service
Step 2 — Install Docker Compose
Install Extra Packages for Enterprise Linux
$ sudo yum install epel-release
Install python-pip
$ sudo yum install -y python-pip
Then install Docker Compose:
$ sudo pip install docker-compose
You will also need to upgrade your Python packages on CentOS 7 to get docker-compose to run successfully:
$ sudo yum upgrade python*
To verify a successful Docker Compose installation, run:
$ docker-compose version
Install Gitlab with docker
sudo docker run -d \
-e GITLAB_OMNIBUS_CONFIG="external_url 'http://192.168.10.51/'; gitlab_rails['lfs_enabled'] = true;gitlab_rails['gitlab_shell_ssh_port'] = 822" \
-p 8443:8443 -p 880:880 -p 822:822 \
--name gitlab \
--restart always \
-v /srv/gitlab/config:/etc/gitlab \
-v /srv/gitlab/logs:/var/log/gitlab \
-v /srv/gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce:latest
Gitlab docker container – backup and restore
Two examples:
- backup and restore GitLab docker container with volumes
- backup and restore only useful data
Gitlab is running in Docker container on server a.example.com. Container was create by command:
docker run --detach --hostname gitlab.example.com \
--publish 192.168.0.101:443:443 \
--publish 192.168.0.101:80:80 \
--publish 192.168.0.101:2222:22 \
--name gitlab-example --restart always \
--volume /storage/gitlab/config:/etc/gitlab \
--volume /storage/gitlab/logs:/var/log/gitlab \
--volume /storage/gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce:latest
Full backup (including docker images)
You need to complete 4 steps:
- backup container gitlab-example
- backup volume /etc/gitlab
- backup volume /var/log/gitlab
- backup volume /var/opt/gitlab Commands:
docker stop gitlab-example
docker commit gitlab-example local/gitlab-example-container-20170417
docker save local/gitlab-example-container-20170417 > /root/gitlab-example-container-20170417.tar
docker run --rm --volumes-from gitlab-example -v $(pwd):/backup ubuntu tar cvf /backup/gitlab-example-volume-etc-20170417.tar /etc/gitlab
docker run --rm --volumes-from gitlab-example -v $(pwd):/backup ubuntu tar cvf /backup/gitlab-example-volume-log-20170417.tar /var/log/gitlab
docker run --rm --volumes-from gitlab-example -v $(pwd):/backup ubuntu tar cvf /backup/gitlab-example-volume-opt-20170417.tar /var/opt/gitlab
Full restore (including docker images)
Restore on second server b.example.com. Example CentOS 7.3:
yum -y install epel-release
yum -y install docker-io
systemctl enable docker
systemctl start docker
Upload 4 files from server a.example.com to b.example.com:
gitlab-example-container-20170417.tar
gitlab-example-volume-etc-20170417.tar
gitlab-example-volume-log-20170417.tar
gitlab-example-volume-opt-20170417.tar
Load image:
docker load -i gitlab-example-container-20170417.tar
Create container:
docker create --hostname gitlab.example.com \
--publish 192.168.0.102:443:443 \
--publish 192.168.0.102:80:80 \
--publish 192.168.0.102:2222:22 \
--name gitlab-example --restart always \
--volume /storage/gitlab/config:/etc/gitlab \
--volume /storage/gitlab/logs:/var/log/gitlab \
--volume /storage/gitlab/data:/var/opt/gitlab \
local/gitlab-example-container-20170417
Restore volumes:
mkdir -p /storage/gitlab/config
mkdir -p /storage/gitlab/logs
mkdir -p /storage/gitlab/data
docker run --rm --volumes-from gitlab-example -v $(pwd):/backup ubuntu bash -c "cd /etc && tar xvf /backup/gitlab-example-volume-etc-20170417.tar --strip 1"
docker run --rm --volumes-from gitlab-example -v $(pwd):/backup ubuntu bash -c "cd /var/log && tar xvf /backup/gitlab-example-volume-log-20170417.tar --strip 2"
docker run --rm --volumes-from gitlab-example -v $(pwd):/backup ubuntu bash -c "cd /var/opt && tar xvf /backup/gitlab-example-volume-opt-20170417.tar --strip 2"
Start container:
docker start gitlab-example
Backup and restore only useful data
Backup cron job daily:
# crontab -e
0 7 * * * /bin/docker exec -i gitlab-example /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1
By default backup files will be saved inside container to: /var/opt/gitlab/backups/
On host system (in my example) backup is located on host system: /storage/gitlab/data/backups/
Restore Find available backup files:
# docker exec -it gitlab-example ls /var/opt/gitlab/backups/
1492443013_2017_04_17_gitlab_backup.tar
Restore backup with time stamp 1492443013_2017_04_17
docker exec -it gitlab-example /opt/gitlab/bin/gitlab-rake gitlab:backup:restore BACKUP=1492443013_2017_04_17