1.docker涉及命令
查看运行镜像
docker ps -a
停止镜像
docker stop id
删除镜像
dcoker rm id
查看容器镜像
docker images
删除镜像
dcoker rmi id
拉取镜像
docker pull gitlab/gitlab-ce:14.0.11-ce.0
2.docker gitllab部署
1.拉取镜像
docker pull gitlab/gitlab-ce:14.0.11-ce.0
2.构建数据目录
cd && mkdir gitlab && cd gitlab && export GITLAB_HOME=/root/gitlab
3.启动容器
docker run -d --name gitlab -p ***:443 -p ****:80 -p **:22 --restart always -v $GITLAB_HOME/config:/etc/gitlab -v $GITLAB_HOME/logs:/var/log/gitlab -v $GITLAB_HOME/data:/var/opt/gitlab --privileged=true gitlab/gitlab-ce:14.0.11-ce.0
4.查看启动日志
docker logs -f gitlab
5.进去容器
docker exec -it gitlab /bin/bash
6.查询gitlab版本
cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
7.查看gitlab运行状态
gitlab-ctl status
3.gitlab初始化密码
1.进入容器
docker exec -it gitlab bash
2.进入bin目录
cd /opt/gitlab/bin
3.执行命令 查看操作命令
gitlab-rails console
4.找到root用户
u=User.where(id:1).first
5.修改密码
u.password='admin@*****'
6.确认密码
u.password_confirmation='admin@Fxtx'
7.保存修改
u.save
4.备份gitlab
gitlab-rake gitlab:backup:create
备份完成会在/var/opt/gitlab/backup目录创建如下格式文件
1644373779_2022_02_09_14.0.11_gitlab_backup.tar
5.复制到docker映射目录
mv 1644373779_2022_02_09_14.0.11_gitlab_backup.tar ~/gitlab/data/backups/
6.停止服务
gitlab-ctl stop sidekiq
7. 还原备份
gitlab-backup restore BACKUP=1644734209_2022_02_13_14.0.11
8.备份遇到问题
Restoring PostgreSQL database gitlabhq_production ... ERROR: must be owner of extension pg_trgm
ERROR: must be owner of extension btree_gist
ERROR: must be owner of extension btree_gist
ERROR: must be owner of extension pg_trgm
解决方案
- 修改postgresql配置
$ vim /var/opt/gitlab/postgresql/data/postgresql.conf
listen_addresses = '*'
# 最下面新增两行
$ vim /var/opt/gitlab/postgresql/data/pg_hba.conf
local all all trust
host all all 127.0.0.1/32 trust
- 重启gitlab服务
$ gitlab-ctl restart
ok: run: logrotate: (pid 29367) 1s
ok: run: nginx: (pid 29371) 0s
ok: run: postgresql: (pid 29389) 0s
ok: run: redis: (pid 29391) 0s
ok: run: sidekiq: (pid 29404) 0s
ok: run: unicorn: (pid 29413) 0s
- 修改gitlab账号为超级用户
$ su - gitlab-psql
$ /opt/gitlab/embedded/bin/psql -h 127.0.0.1 gitlabhq_production
psql (9.2.8)
Type "help" for help.
gitlabhq_production=# ALTER USER gitlab WITH SUPERUSER;
ALTER ROLE
gitlabhq_production=# \q
再次恢复数据已不报错
备份完成修改localtion ip
vim /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml
## GitLab settings
gitlab:
## Web server settings (note: host is the FQDN, do not include http://)
host: localhost >> 这里改为主机的IP即可
port: 80
https: false# Uncommment this line below if your ssh host is different from HTTP/HTTPS one
# (you'd obviously need to replace ssh.host_example.com with your own host).
# Otherwise, ssh host will be set to the `host:` value above
重启gitlab
gitlab-ctl restart
参考链接:
https://www.jianshu.com/p/09a2b0c25ecd
https://www.cnblogs.com/kaneyang/p/7090923.html