问题描述
我遇到一个问题,在发出docker build命令时收到以下错误:-
I am experiencing an issue where I receive the following error when issuing the docker build command:-
curl: (6) Could not resolve host: dl.yarnpkg.com
gpg: no valid OpenPGP data found.
这是我的Dockerbuild文件
Here is my Dockerbuild file
# Base image
FROM ruby:2.5.0
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -
RUN curl -fsSL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee
/etc/apt/sources.list.d/yarn.lisT
RUN apt-get update
RUN apt-get install -qq -y build-essential libpq-dev nodejs yarn
在docker外部运行时,命令成功完成。
The commands complete successfully when run outside of docker.
为了解决问题,我尝试了以下操作
In order to resolve the issues I have tried the following
- 将DNS服务器添加到/etc/docker/daemon.json-相同问题
- 取消注释/ etc / default / docker中的DOCKER_OPTS =-dns 8.8.8.8 --dns 8.8.4.4行-相同问题
- 替换我在/etc/resolv.conf中本地使用的DNS服务器-同样的问题。
我尝试了Google的DNS服务器和OpenDNS,以及多个ISP,具体取决于运行命令的位置
I have tried DNS servers from Google and OpenDNS, as well as multiple ISPs depending on the location im running the command from
Laptop运行的是Ubuntu 16:04,Docker版本为18.06.0-ce,内部版本为0ffa825
Laptop is running Ubuntu 16:04 with Docker version 18.06.0-ce, build 0ffa825 installed.
使用以下命令也会失败
FROM ruby:2.5.0
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
导致以下错误
W: Failed to fetch http://deb.debian.org/debian/dists/stretch/InRelease Temporary failure resolving 'deb.debian.org'
W: Failed to fetch http://deb.debian.org/debian/dists/stretch-updates/InRelease Temporary failure resolving 'deb.debian.org'
W: Failed to fetch http://security.debian.org/dists/stretch/updates/InRelease Temporary failure resolving 'security.debian.org'
W: Some index files failed to download. They have been ignored, or old ones used instead.
所以我知道这不是dl.yarnpkg.com主机的问题。
So I know this isnt just a problem iwth the dl.yarnpkg.com host.
使用no-cache选项运行docker build命令没有区别。
Running the docker build command with the no-cache option makes no difference.
推荐答案
我在Docker和Ubuntu 16.04上使用了Docker,有时我也遇到名称解析问题。
I am using Docker with Ubuntu 16.04 and sometimes I have name resolution problems too.
唯一通过添加-network的方法= host
。我不太确定发生了什么,但似乎需要使用它来使用计算机名称解析功能。希望对您有所帮助。
The only thing that made it through was adding --network=host
when building. I'm not really sure what's going on but it seems it needs this to use your computer name resolution capabilities. I hope it helps.
这篇关于在Docker构建期间名称解析失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!