本地主机上带有 Docker runner 的 GitLab:如何将主机暴露给容器?
GitLab with Docker runner on localhost: how to expose host to container?
我正在学习使用 GitLab CI。
刚才我在本地主机上使用 GitLab (external_url "http://localhost"
)。我已经注册了 Docker 运行ner with vanilla ubuntu:20.04
图像并尝试 运行 一些测试工作。
唉,它试图从容器中的本地主机存储库克隆我的存储库,但无法做到,因为我的本地主机的端口 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:80?
好吧,我已经应付了这些东西。
我已将 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"
我正在学习使用 GitLab CI。
刚才我在本地主机上使用 GitLab (external_url "http://localhost"
)。我已经注册了 Docker 运行ner with vanilla ubuntu:20.04
图像并尝试 运行 一些测试工作。
唉,它试图从容器中的本地主机存储库克隆我的存储库,但无法做到,因为我的本地主机的端口 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:80?
好吧,我已经应付了这些东西。
我已将 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"