add hosts redirection in docker

2019-03-19 08:54发布

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 :/ .

2条回答
三岁会撩人
2楼-- · 2019-03-19 09:04

if you want to use dns in docker use dns-gen follow these simple steps by this step you can assign host name to multi docker containers. 1. First know your docker IP by Publishing this command

/sbin/ifconfig docker0 | grep "inet" | head -n1 | awk '{ print $2}' | cut -d: -f2

  1. now note the output ip and time to start dns-gen container(ps: don't forget to add docker ip you get by issuing above command before :53:53)

docker run --detach \ --name dns-gen \ --publish dockerip:53:53/udp \ --volume /var/run/docker.sock:/var/run/docker.sock \ jderusse/dns-gen

  1. Last thing: Register you new DnsServer in you resolv.conf

echo "nameserver dockerip" | sudo tee --append /etc/resolvconf/resolv.conf.d/head sudo resolvconf -u

Now you should be able to access your docker container in browser :- http://containername.docker

Hope it works.. Thanks..

Shubhankit

查看更多
Lonely孤独者°
3楼-- · 2019-03-19 09:13

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.

查看更多
登录 后发表回答