iT邦幫忙

16

Docker Compose 建立 GitLab 容器,執行器 Runner 運行流水線問題

  • 分享至 

  • xImage

我的作業系統是 Windows 11
用 Docker Compose 建立一個 GitLab 及 GitLab Runner的容器
docker-compose.yml 檔案內容如下

version: '3.8'

services:
  gitlab:
    image: gitlab/gitlab-ce:latest
    container_name: gitlab
    restart: always
    hostname: gitlab
    ports:
      - "80:80"
      - "443:443"
      - "22:22"
    volumes:
      - .gitlab-config:/etc/gitlab
      - .gitlab-logs:/var/log/gitlab
      - .gitlab-data:/var/opt/gitlab
    shm_size: '256m'
    networks:
      - gitlab-network

  gitlab-runner:
    image: gitlab/gitlab-runner:latest
    container_name: gitlab-runner
    restart: always
    depends_on:
      - gitlab
    volumes:
      - .gitlab-runner-config:/etc/gitlab-runner
      - /var/run/docker.sock:/var/run/docker.sock
    networks:
      - gitlab-network

networks:
  gitlab-network:
    driver: bridge

執行器Runner狀態
https://ithelp.ithome.com.tw/upload/images/20250919/20061169jTmylMwOkH.jpg
執行器Runner設定內容
https://ithelp.ithome.com.tw/upload/images/20250919/20061169Wco9o51qO6.jpg
建立了一個專案 ci-cd-demo
.gitlab-ci.yml內容如下

helloworld:
  script:
    - echo "hello world, GitLab!"   

執行錯誤畫面
https://ithelp.ithome.com.tw/upload/images/20250919/20061169J6eYzotdzf.jpg
錯誤訊息
fatal: unable to access 'http://gitlab/root/ci-cd-demo.git/': Failed to connect to gitlab port 80 after 3 ms: Could not connect to server
Retrying in 5s
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1

請問各位前輩該如何排除問題?

2025/09/22問題補充:
gitlab 可以 ping 到 gitlab-runner
https://ithelp.ithome.com.tw/upload/images/20250922/20061169pQowtZHsnE.jpg
gitlab-runner 可以 ping 到 gitlab
https://ithelp.ithome.com.tw/upload/images/20250922/20061169VqGgcNeKDd.jpg
gitlab-runner的config.toml內容如下

concurrent = 1
check_interval = 0
shutdown_timeout = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "gitlab-runner-1"
  url = "http://gitlab"
  id = 1
  token = "glrtr-rnjJjFJYikUjtJ-MwE9x"
  token_obtained_at = 2025-09-18T06:25:11Z
  token_expires_at = 0001-01-01T00:00:00Z
  executor = "docker"
  [runners.cache]
    MaxUploadedArchiveSize = 0
    [runners.cache.s3]
    [runners.cache.gcs]
    [runners.cache.azure]
  [runners.docker]
    tls_verify = false
    image = "alpine:latest"
    privileged = false
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/cache"]
    shm_size = 0
    network_mtu = 0
看更多先前的討論...收起先前的討論...
Jasper iT邦新手 5 級 ‧ 2025-09-20 16:46:34 檢舉
進去 gitlab-runner container 確認是否可以連到 gitlab

另外可以看一下你的 .gitlab-runner-config 內容嗎?
可以參考一下官方文件 https://docs.gitlab.com/runner/executors/docker/#network-configurations
Hi Jasper,
相關訊息已經補充在問題下方
再麻煩您
nj iT邦新手 5 級 ‧ 2025-09-25 10:49:05 檢舉
你的http://gitlab 可以連到gitlab?
boicelu iT邦新手 5 級 ‧ 2025-09-26 11:00:50 檢舉
感覺是gitlab缺了.com 你用curl測看看?
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
boicelu
iT邦新手 5 級 ‧ 2025-09-26 11:11:29

看官方教程
https://docs.gitlab.com/install/docker/installation/

應該是可以考慮加上

environment:
  GITLAB_OMNIBUS_CONFIG: |
    # Add any other gitlab.rb configuration here, each on its own line
    external_url 'https://gitlab.example.com'

試試看吧

我要發表回答

立即登入回答