本地主机上带有Docker runner的GitLab:如何向容器公开主机



我正在学习使用GitLab CI.

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

遗憾的是,它试图从容器中的localhost存储库克隆我的repo,但无法执行,因为从容器中看不到我的localhost端口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

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

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

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

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

[[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"

最新更新