DEV Community

Cover image for This is how I dealt with "Temporary failure resolving" issue during docker build
Axlyted
Axlyted

Posted on • Updated on

This is how I dealt with "Temporary failure resolving" issue during docker build

Greetings ladies and gentlemen,

If you found this article, you most likely came across this nasty error:

Step 3/8 : RUN apt-get update && apt-get install gcc python3-dev mariadb-client mariadb-server -y
 ---> Running in 7adba5657671
Err:1 http://deb.debian.org/debian buster InRelease
  Temporary failure resolving 'deb.debian.org'
Err:2 http://security.debian.org/debian-security buster/updates InRelease
  Temporary failure resolving 'security.debian.org'
Err:3 http://deb.debian.org/debian buster-updates InRelease
  Temporary failure resolving 'deb.debian.org'
Reading package lists...
W: Failed to fetch http://deb.debian.org/debian/dists/buster/InRelease  Temporary failure resolving 'deb.debian.org'
W: Failed to fetch http://security.debian.org/debian-security/dists/buster/updates/InRelease  Temporary failure resolving 'security.debian.org'
W: Failed to fetch http://deb.debian.org/debian/dists/buster-updates/InRelease  Temporary failure resolving 'deb.debian.org'
W: Some index files failed to download. They have been ignored, or old ones used instead.
Reading package lists...
Building dependency tree...
Reading state information...
Package python3-dev is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'python3-dev' has no installation candidate
E: Unable to locate package mariadb-client
E: Unable to locate package mariadb-server
ERROR: Service 'process-test-results' failed to build : The command '/bin/sh -c apt-get update && apt-get install gcc python3-dev mariadb-client mariadb-server -y' returned a non-zero code: 100
Enter fullscreen mode Exit fullscreen mode

It most likely popped up during a docker build or docker-compose build.

You've tried to figure it out but Google and StackOverFlow didn't give you much to work with. I know, I've been there.

Let's run the following command:

 cat /etc/resolv.conf
Enter fullscreen mode Exit fullscreen mode

If that's what you've got:

# Please ignore all the lines that start with a hash symbol
nameserver 127.0.0.53
Enter fullscreen mode Exit fullscreen mode

You came to the right place. Apparently, there's an open bug related to Docker and DNS 172.0.0.53 here.

You most likely using Ubuntu 18.04 / 20.04 which comes pre installed with systemd, which.. also contain systemd-resolved and that's why it set to nameserver 127.0.0.53.

Basically, during a build, a docker container is taking that DNS and trying to use it inside a container. But it can't.

image

Well, now when we sort of knows what's the issue, we can finally solve it.

Before you start, make sure you know what you're doing. messing up with your DNS can leave your host without internet access which can be really inconvenient.

In any case, if that happened, you better check /etc/resolv.conf and make sure that it has these lines:

nameserver 8.8.8.8
nameserver 8.8.4.4
Enter fullscreen mode Exit fullscreen mode
  1. Stop and disable systemd-resolved
sudo systemctl disable systemd-resolved
sudo systemctl stop systemd-resolved
Enter fullscreen mode Exit fullscreen mode
  1. Set Network Manager to recognize systemd-resolved as disabled
vim /etc/NetworkManager/NetworkManager.conf
# And then change dns to default. ex:
# dns=default
Enter fullscreen mode Exit fullscreen mode
  1. Remove the old /etc/resolv.conf file
rm /etc/resolv.conf
Enter fullscreen mode Exit fullscreen mode
  1. Restart Network Manager
sudo systemctl restart NetworkManager
Enter fullscreen mode Exit fullscreen mode
  1. Use dnsmasq to add google's DNS server into /etc/resolv.conf since it can't be modified directly
sudo vim /etc/dnsmasq.conf
# Add to the end of the file:
server=8.8.8.8
server=8.8.4.4
Enter fullscreen mode Exit fullscreen mode

Discussion (0)