Name resolution failing during docker build

2020-05-01 05:11发布

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.

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

The commands complete successfully when run outside of docker.

In order to resolve the issues I have tried the following

  1. Adding DNS servers to /etc/docker/daemon.json - same issue
  2. Uncommenting the DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4" line in /etc/default/docker - same issue
  3. Replacing the DNS servers I use locally in /etc/resolv.conf - same issue.

I have tried DNS servers from Google and OpenDNS, as well as multiple ISPs depending on the location im running the command from

Laptop is running Ubuntu 16:04 with Docker version 18.06.0-ce, build 0ffa825 installed.

Using the following also fails

FROM ruby:2.5.0
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs

causing the following error

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.

So I know this isnt just a problem iwth the dl.yarnpkg.com host.

Running the docker build command with the no-cache option makes no difference.

标签: docker
1条回答
Deceive 欺骗
2楼-- · 2020-05-01 05:54

I am using Docker with Ubuntu 16.04 and sometimes I have name resolution problems too.

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.

查看更多
登录 后发表回答