背景
上个月用docker部署了一个gitlab-jh的服务,给小组上传代码使用,这个月由于机器故障重装系统,当我重新部署好gitlab后发现docker容器启动后会闪退,为寻因果,故作此篇
- docker-compose.yml 文件
sh
version: '3.6'
services:
web:
image: 'registry.gitlab.cn/omnibus/gitlab-jh:latest'
#容器退出后会自动重启
restart: always
hostname: 'gitlab.example.com'
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://10.20.18.181:8929'
gitlab_rails['gitlab_shell_ssh_port'] = 2224
ports:
# 宿主机与容器内端口映射
- '8929:8929'
- '2224:22'
volumes:
- '$GITLAB_HOME/config:/etc/gitlab'
- '$GITLAB_HOME/logs:/var/log/gitlab'
- '$GITLAB_HOME/data:/var/opt/gitlab'
shm_size: '256m'
- install_gitlab.sh 脚本
sh
#! /bin/bash
export GITLAB_HOME=/archive/.gitlab
docker compose up -d
原因分析
- 启动容器后,容器闪退
sh
# ./install_gitlab.sh
[+] Running 1/1
✔ Container gitlab-web-1 Started 0.5s
# docker ps
CONTAINER ID IMAGE COMMAND CREATED
STATUS PORTS
NAMES
e307aa90d5dd registry.gitlab.cn/omnibus/gitlab-jh:latest "/assets/wrapper" 3 seconds ago Up 2 seconds (health: starting) 80/tcp, 443/tcp, 0.0.0.0:8929->8929/tcp, :::8929->8929/tcp, 0.0.0.0:2224->22/tcp, :::2224->22/tcp gitlab-web-1
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- 查看日志
日志显示目前gitlab-jh版本是17.0.1,最后一行又显示我正从16.10.3升级到17.0.1
sh
# docker logs e30
Thank you for using GitLab Docker Image!
Current version: gitlab-jh=17.0.1-jh.0
Configure GitLab for your system by editing /etc/gitlab/gitlab.rb file
And restart this container to reload settings.
To do it use docker exec:
docker exec -it gitlab editor /etc/gitlab/gitlab.rb
docker restart gitlab
For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md
If this container fails to start due to permission problems try to fix it by executing:
docker exec -it gitlab update-permissions
docker restart gitlab
Cleaning stale PIDs & sockets
It seems you are upgrading from 16.10.3-jh to 17.0.1.
It is required to upgrade to the latest 16.11.x version first before proceeding.
Please follow the upgrade documentation at https://docs.gitlab.com/ee/update/index.html#upgrading-to-a-new-major-version
- 在其他目录重新部署gitlab,发现服务正常运行,初步判断是宿主机映射目录的问题
sh
# ls
config data logs
- 对目录分析,最终查看到是data中版本与镜像版本不匹配
data目录中子目录对应的版本号都是16.x
sh
# find . -name "*VERSION*"
./gitaly/VERSION
./gitlab-workhorse/VERSION
./gitlab-kas/VERSION
./postgresql/data/PG_VERSION
./postgresql/data/base/12974/PG_VERSION
./postgresql/data/base/16386/PG_VERSION
./postgresql/data/base/1/PG_VERSION
./postgresql/data/base/12973/PG_VERSION
./postgresql/VERSION
./nginx/VERSION
./gitlab-exporter/RUBY_VERSION
./gitlab-rails/RUBY_VERSION
./gitlab-rails/VERSION
# cat gitlab-workhorse/VERSION
gitlab-workhorse (v16.10.3-jh)-(20240417.013513)
a# cat gitlab-rails/VERSION
16.10.3-jh
# cat gitlab-kas/VERSION
kas version v16.10.1, commit: 8892127a, built: 20240417.013045
原因总结
日志显示目前gitlab-jh版本是17.0.1,最后一行又显示我正从16.10.3升级到17.0.1
data目录中子目录对应的版本号都是16.x
镜像设置为latest,故每次部署时,默认拉最新镜像,但是我的data数据是旧版本的数据
根据背景、日志以及data目录中的版本号可以判定是数据的版本和镜像的版本不匹配导致
解决方案
重新将镜像的版本恢复到16.10.3,修改docker-compose.yml 文件的image字段,将镜像tag从latest改为16.10.3,后续再正常升级即可
sh
# cat docker-compose.yml
version: '3.6'
services:
web:
#image: 'registry.gitlab.cn/omnibus/gitlab-jh:latest'
image: 'registry.gitlab.cn/omnibus/gitlab-jh:16.10.3'
restart: always
hostname: 'gitlab.example.com'
environment:
GITLAB_OMNIBUS_CONFIG: |
# 容器内端口改为8929
external_url 'http://10.20.18.181:8929'
# (可能也可不配置?)增加gitlab shell端口号,22和2224都可以使用
gitlab_rails['gitlab_shell_ssh_port'] = 2224
ports:
# 宿主机与容器内端口映射
- '8929:8929'
- '2224:22'
volumes:
- '$GITLAB_HOME/config:/etc/gitlab'
- '$GITLAB_HOME/logs:/var/log/gitlab'
- '$GITLAB_HOME/data:/var/opt/gitlab'
shm_size: '256m'