docker容器化安装gitlab
前提
1、docker组件已经安装,参照:CentOS7下安装Docker
2、docker-compose已安装完成,参照:CentOS7下安装docker-compose
安装过程
1、将备份数据通过NFS添加到远程
搭建NFS服务器请参照《CentOS7下搭建NFS服务及配置使用》,不使用网络备份可省略这一步。
mount 10.220.96.202:/data/share /mnt/backups/
2、建立docker-compose.yml
内容参考如下:
web:
image: 'gitlab/gitlab-ce:12.2.4-ce.0'
restart: always
container_name: gitlab
hostname: '10.220.96.205'
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://10.220.96.205:8020'
external_url 'https://10.220.96.205:8021'
gitlab_rails['gitlab_shell_ssh_port'] = 8022
gitlab_rails['backup_path'] = "/backups"
nginx['listen_port'] = 8021
nginx['ssl_certificate'] = "/var/opt/gitlab/certs/registry.tpri.com.cn.crt"
nginx['ssl_certificate_key'] = "/var/opt/gitlab/certs/registry.tpri.com.cn.key"
ports:
- '8020:8020'
- '8021:8021'
- '8022:22'
volumes:
- '/data/gitlab/config:/etc/gitlab'
- '/data/gitlab/logs:/var/log/gitlab'
- '/data/gitlab/data:/var/opt/gitlab'
- '/mnt/backups:/backups'
- '/etc/localtime:/etc/localtime:ro'
3、启动gitlab
在docker-compose.yml文件同文件夹下执行以下命令
docker-compose up -d
4、设置自动备份
sudo crontab -e -u root
加入以下内容
# 每天早上2:00备份gitlab的配置文件和数据0 2 * * * docker exec -t gitlab gitlab-ctl backup-etc /backups && docker exec -t gitlab gitlab-backup create