GitLab 在本地主机上使用 Docker 运行程序:如何将主机暴露给容器?

Fel*_*lix 3 continuous-integration gitlab docker

我正在学习使用 GitLab CI。

刚才我在 localhost ( external_url "http://localhost") 上使用 GitLab。我已经使用普通ubuntu:20.04映像注册了一个 Docker 运行程序,并尝试在其上运行一些测试作业。

唉,它尝试从容器中的本地主机存储库克隆我的存储库,但无法做到这一点,因为我的本地主机的端口 80 在容器中不可见。

Running with gitlab-runner 13.5.0 (ece86343)
  on docker0 x8pHJPn7
Preparing the "docker" executor
Using Docker executor with image ubuntu:20.04 ...
Pulling docker image ubuntu:20.04 ...
Using docker image sha256:d70eaf7277eada08fca944de400e7e4dd97b1262c06ed2b1011500caa4decaf1 for ubuntu:20.04 with digest ubuntu@sha256:fff16eea1a8ae92867721d90c59a75652ea66d29c05294e6e2f898704bdb8cf1 ...
Preparing environment
Running on runner-x8phjpn7-project-6-concurrent-0 via gigant...
Getting source from Git repository
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in /builds/root/ci_fuss/.git/
fatal: unable to access 'http://localhost:80/root/ci_fuss.git/': Failed to connect to localhost port 80: Connection refused
Uploading artifacts for failed job
Uploading artifacts...
WARNING: report.xml: no matching files             
ERROR: No files to upload                          
Cleaning up file based variables
ERROR: Job failed: exit code 1
Run Code Online (Sandbox Code Playgroud)

我的 Docker 运行程序如何将主机的 localhost:80 公开为容器的 localhost:80?

Fel*_*lix 8

好吧,我已经处理了这些事情了。

我已添加network_mode = "host"到我的运行程序配置中,/etc/gitlab-runner/config.toml以使我的 docker 使用主机网络连接。

此外,我还添加了--pull_policy="if-not-present"首先在本地搜索容器映像,然后在远程存储库中搜索。

[[runners]]
  name = "docker0"
  url = "http://localhost/"
  token = "TTBRFis_W_yJJpN1LLzV"
  executor = "docker"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
    [runners.cache.azure]
  [runners.docker]
    tls_verify = false
    image = "exposed_ctr:latest"
    privileged = false
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/cache"]
    shm_size = 0
    network_mode = "host"
    pull_policy = "if-not-present"
Run Code Online (Sandbox Code Playgroud)