git 无法解析 docker 中的主机
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47177850/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Could not resolve host in docker
提问by Xero
I'm trying to do an jenkins on docker, on my machine (Ubuntu).
我正在尝试在我的机器(Ubuntu)上的 docker 上执行 jenkins。
I have to access to the git repo, in my company. But in jenkins, I get this error :
我必须访问我公司的 git repo。但在詹金斯,我得到这个错误:
Could not resolve host: gogs.mycompany.com
无法解析主机:gogs.mycompany.com
I think this is an DNS error, so I tried to launch my docker like that (with --dns and --dns-search)
我认为这是一个 DNS 错误,所以我尝试像这样启动我的 docker(使用 --dns 和 --dns-search)
sudo docker run -p 8080:8080 -p 50000:50000 -v /home/xero/jenkins:/var/jenkins_home --name=myproject-jenkins2 --dns=127.0.1.1 --dns-search=mycompany.lan jenkins
sudo docker run -p 8080:8080 -p 50000:50000 -v /home/xero/jenkins:/var/jenkins_home --name=myproject-jenkins2 --dns=127.0.1.1 --dns-search=mycompany.lan jenkins
Here my /etc/resolv.conf :
这是我的 /etc/resolv.conf :
nameserver 127.0.1.1
search mycompany.lan
名称服务器 127.0.1.1
搜索 mycompany.lan
What I'm doing wrong ?
我做错了什么?
采纳答案by Xero
The DNS was wrong. (--dns=127.0.1.1)
DNS 错误。(--dns=127.0.1.1)
This DNS server, is an internal DNS, Dnsmasq, it's a DNS forwarder.
这个 DNS 服务器,是一个内部 DNS,Dnsmasq,它是一个 DNS 转发器。
So I needed to know the real internal DNS server :
所以我需要知道真正的内部 DNS 服务器:
nmcli dev show | grep DNS
And add the right address (10.0.1.1 in my case) :
并添加正确的地址(在我的例子中是 10.0.1.1):
sudo docker run -p 8080:8080 -p 50000:50000 -v /home/xero/jenkins:/var/jenkins_home --name=myproject-jenkins2 --dns=10.0.1.1 jenkins
sudo docker run -p 8080:8080 -p 50000:50000 -v /home/xero/jenkins:/var/jenkins_home --name=myproject-jenkins2 --dns=10.0.1.1 jenkins