gitlab-jh的docker容器自动退出/gitlab镜像版本/升级问题

背景

上个月用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'

参考

  1. 极狐GitLab Docker 镜像
  2. 使用 Docker compose 升级极狐GitLab
相关推荐
猫吃了源码13 小时前
k9s简介和安装
linux·docker·kubernetes
云原生指北14 小时前
Docker Sandboxes 上手:从安装到第一次跑 Agent
运维·docker·容器
ziyun66688814 小时前
Docker 容器化 Web 服务架构搭建与自动化运维项目
运维·docker·架构
Jeanyia15 小时前
GitLab 配套 Git 常用命令
git·gitlab
骇客野人17 小时前
Docker Compose 部署多个独立 Jar 服务完整实操步骤
docker·容器·jar
云川之下19 小时前
【k8s】Docker inspect 命令
docker·容器·kubernetes
极小狐20 小时前
极狐GitLab 补丁版本:19.2.1、19.1.3、19.0.5
网络·安全·gitlab·极狐gitlab·安全更新·补丁版本
倔强的石头10620 小时前
飞牛OS部署Mtab:Docker搭建自托管书签导航并实现远程访问
运维·docker·容器
生活爱好者!1 天前
居家观影再升级,docker 部署 DecoTV 影音界面
运维·docker·容器
apgk11 天前
基于Canal实现mysql数据同步到消息队列(RabbitMQ/Kafka)详细操作教程
docker·kafka·rabbitmq