GitLab Runner注册成功后Docker容器自动停止问题咨询
GitLab Runner注册后容器自动停止问题
问题描述
在版本为3.6的docker-compose.yaml中配置了GitLab Runner的非交互式注册命令,注册成功后容器直接停止,无法保持运行状态。
现有docker-compose配置
volumes: portainer_data: networks: mnt_network: ipam: config: - subnet: 172.20.0.0/24 services: executor_docker_kaniko: container_name: ${CONTAINER_NAME_PREFIX}kaniko image: gitlab/gitlab-runner:alpine3.13-v14.8.3 #restart: unless-stopped depends_on: - gitlab volumes: - ./workspace:/home/gitlab-runner #- ./executor_docker/config/config.json:/kaniko/.docker/config.json #- ./kaniko/ssl:/kaniko/ssl/certs #- /srv/gitlab/config/ssl:/kaniko/ssl/certs - /srv/gitlab/config/ssl:/etc/gitlab-runner/certs - /var/run/docker.sock:/var/run/docker.sock - ./executor_docker/config/:/etc/gitlab-runner #build: # context: ./executor_docker/build/ # dockerfile: Dockerfile.txt command: register --non-interactive --executor "docker" --docker-image gcr.io/kaniko-project/executor:debug --tls-ca-file=/etc/gitlab-runner/certs/gitlab.blk-astra-v01.crt --url=https://gitlab.blk-astra-v01/ --registration-token=${PROJECT_REGISTRATION_TOKEN} --description "executor_docker-kaniko" --tag-list "linux" --run-untagged="true" \ --maintenance-note "Free-form maintainer notes about this runner" \ --locked="false" \ --access-level="not_protected" # 下面的命令注册一个执行器为docker、镜像为kaniko的runner #command:> # -run # - --user=gitlab-runner # - --working-directory=/home/gitlab-runner extra_hosts: - "${GITLAB_SERVER_NAME}:192.168.100.224" - "blk-astra-v01:192.168.100.224"
Docker日志
Runtime platform arch=amd64 os=linux pid=7 revision=16ae0625 version=14.8.3 运行在系统模式下。 注册Runner...成功 runner=xW84U-_X Runner注册成功。您可以启动它,如果它已在运行,配置会自动重载!
问题原因及解决方法
- 原因:当前
command仅执行注册操作,注册完成后进程直接结束,容器因主进程退出而停止。GitLab Runner的默认启动命令是run,用于持续运行Runner服务。 - 解决方法:
- 合并注册与启动命令:通过复合命令让容器先完成注册(若未注册),再启动Runner服务,修改
command配置如下:command: > bash -c " if [ ! -f /etc/gitlab-runner/config.toml ]; then gitlab-runner register --non-interactive --executor 'docker' --docker-image gcr.io/kaniko-project/executor:debug --tls-ca-file=/etc/gitlab-runner/certs/gitlab.blk-astra-v01.crt --url=https://gitlab.blk-astra-v01/ --registration-token=${PROJECT_REGISTRATION_TOKEN} --description 'executor_docker-kaniko' --tag-list 'linux' --run-untagged='true' --maintenance-note 'Free-form maintainer notes about this runner' --locked='false' --access-level='not_protected'; fi; gitlab-runner run --user=gitlab-runner --working-directory=/home/gitlab-runner " - 启用重启策略:取消注释
restart: unless-stopped,确保容器意外停止后能自动重启。 - 逻辑说明:添加
if [ ! -f /etc/gitlab-runner/config.toml ]判断,避免容器重启时重复执行注册命令导致报错。
- 合并注册与启动命令:通过复合命令让容器先完成注册(若未注册),再启动Runner服务,修改
内容的提问来源于stack exchange,提问作者Limedok Club
相关产品推荐
相关产品推荐

