gpt4 book ai didi

docker - Docker-在DNS缓存中未找到主机名

转载 作者:行者123 更新时间:2023-12-02 18:32:05 25 4
gpt4 key购买 nike

我正在使用Dockerfile来访问我们的公司Nexus(npm)服务器以执行“npm install”命令。我看到了:

* Hostname was NOT found in DNS cache
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 216.xxx.xxx.xxx...
* connect to 216.xxx.xxx.xxx port 443 failed: Connection refused
* Failed to connect to nexus.<something>.com port 443: Connection refused
* Closing connection 0
curl: (7) Failed to connect to nexus.<something>.com port 443: Connection refused

我可以解决www.google.com。我可以从我的本地邮箱访问并使用我们的公司NPM注册信息。似乎只有我们内部的DNS名称是问题,并且仅在尝试从Docker容器内部访问它们时才出现问题。我已经用Google搜索,但无法确定为解决此问题而需要进行的更改。

Dockerfile(我修剪了不相关的命令):
FROM node:6.3
RUN curl -k -v https://www.google.com
RUN curl -k -vv https://nexus.<something>.com/repository/npm-all/

curl 到google.com成功。对我们内部仓库的 curl 失败。

我用命令启动它:
docker build .

/etc/resolv.conf的内容
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 127.0.1.1

我正在运行Ubuntu 15.10。



@BMitch是正确的。通过添加与公司网络关联的dns服务器地址来修改/etc/resolv.conf的内容。对于Ubuntu 15+(我正在运行gnome3),您的配置文件将被网络管理器覆盖,因此无法进行手动编辑。通过网络管理器gui进行更改。打开“网络设置”,选择“DNS”选项卡并添加服务器。

最佳答案

本地DNS地址是您面临的问题。容器无法从容器内部连接到本地ip。解决方案是在docker run中传递DNS服务器的IP地址,或更新/etc/resolv.conf使其指向非回送IP地址。

Docker's DNS documentation:

Filtering is necessary because all localhost addresses on the host are unreachable from the container’s network. After this filtering, if there are no more nameserver entries left in the container’s /etc/resolv.conf file, the daemon adds public Google DNS nameservers (8.8.8.8 and 8.8.4.4) to the container’s DNS configuration. If IPv6 is enabled on the daemon, the public IPv6 Google DNS nameservers will also be added (2001:4860:4860::8888 and 2001:4860:4860::8844).

Note: If you need access to a host’s localhost resolver, you must modify your DNS service on the host to listen on a non-localhost address that is reachable from within the container.

关于docker - Docker-在DNS缓存中未找到主机名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38962676/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com