在docker中添加主机重定向 [英] add hosts redirection in docker
问题描述
对于访问我的gitlab,我使用域git.local(重定向到我的VM在我的电脑上,重定向到我的虚拟机中的127.0.0.1。)
当我启动测试时,测试返回:
致命:无法访问' http:// gitlab-ci-token:xxxxxx@git.local/thib3113/ESCF.git/ ':无法解析主机'git.local'
所以我的问题是:如何为git.local添加重定向到容器IP?我看到docker的 arg -h< host>
,但是我不知道如何告诉gitlab使用这个参数。或者可能是一个配置来告诉docker使用容器dns?
我看到这样:如何让Docker Gitlab CI转接器访问其父主机上的Git? / a>
但同样的问题,我不知道如何添加参数:/。
根据 GitLab CI Runner Advanced配置,您可以尝试在GitLab CI转轮中使用 extra_hosts
param。
在 /etc/gitlab-runner/config.toml
:
[[runners]]
url =http:// localhost / ci
token =TOKEN
name =my_runner
executor =docker
[runners.docker]
host =tcp://< DOCKER_DAEMON_IP>:2375
image =...
...
extra_hosts = [localhost:192.168.0.39]
有了这个例子, git将尝试从 localhost 克隆,它将使用 192.168.0.39
作为此主机名的IP。
I use gitlab in a Virtual machine . And I will use gitlab-ci (in the same VM), with docker .
For access to my gitlab, I use the domain git.local ( redirect to my VM on my computer, redirect to the 127.0.0.1 in my VM ).
And when I launch the tests, the test return :
fatal: unable to access 'http://gitlab-ci-token:xxxxxx@git.local/thib3113/ESCF.git/': Couldn't resolve host 'git.local'
So My question is: How add a redirection for git.local to the container IP ? I see the arg -h <host>
for docker, but I don't know how to tell gitlab to use this argument. Or maybe a configuration for tell docker to use the container dns?
I see this: How do I get a Docker Gitlab CI runner to access Git on its parent host? but same problem, I don't know how add argument :/ .
According to the GitLab CI Runner Advanced configuration, you can try to play with the extra_hosts
param in your GitLab CI runner.
In /etc/gitlab-runner/config.toml
:
[[runners]]
url = "http://localhost/ci"
token = "TOKEN"
name = "my_runner"
executor = "docker"
[runners.docker]
host = "tcp://<DOCKER_DAEMON_IP>:2375"
image = "..."
...
extra_hosts = ["localhost:192.168.0.39"]
With this example, when inside the container running the test git will try to clone from localhost, it will use the 192.168.0.39
as IP for this hostname.
这篇关于在docker中添加主机重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!