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
相关推荐
Good_Starry7 小时前
Git介绍--github/gitee/gitlab使用
git·gitee·gitlab·github
wusam7 小时前
螺蛳壳里做道场:老破机搭建的私人数据中心---Centos下Docker学习04(环境准备)
学习·docker·centos
wusam10 小时前
螺蛳壳里做道场:老破机搭建的私人数据中心---Centos下Docker学习03(网络及IP规划)
运维·服务器·网络·docker·容器
一直在进步的派大星10 小时前
Docker 从安装到实战
java·运维·docker·微服务·容器
陌殇殇殇15 小时前
使用GitLab CI构建持续集成案例
运维·ci/cd·云原生·容器·kubernetes·gitlab
吕玉生15 小时前
基于GitLab 的持续集成环境
ci/cd·gitlab
技术钱15 小时前
docker简介
运维·docker·容器
roman_日积跬步-终至千里16 小时前
【docker】docker常见命令
运维·docker·容器
tangdou36909865520 小时前
Docker系列-超级详细教你Linux安装并使用docker compose,如何使用docker-compose安装sqlserver
docker·容器·sql server
tangdou36909865520 小时前
手把手非常详细图文并茂教你 Docker 部署 SQL Server
docker·容器·sql server