This is how I dealt with "Temporary failure resolving" issue during docker build
Tags: docker, ubuntu, dns, issue
Published: 2021-08-27 16:52:21

Greetings ladies and gentlemen,

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


```Python
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
```

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:

```Bash
 cat /etc/resolv.conf
```


If that's what you've got:
```Bash
# Please ignore all the lines that start with a hash symbol
nameserver 127.0.0.53
```

You came to the right place. Apparently, there's an open bug related to Docker and DNS 172.0.0.53 [here.](https://github.com/docker/for-linux/issues/979)

You most likely using Ubuntu 18.04 / 20.04 which comes pre installed with systemd, which.. also contain [systemd-resolved](https://wiki.archlinux.org/title/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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x7codv53o2yoahsm194x.png)

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:
```Bash
nameserver 8.8.8.8
nameserver 8.8.4.4
```


1. Stop and disable systemd-resolved

```Bash
sudo systemctl disable systemd-resolved
sudo systemctl stop systemd-resolved
```

2. Set Network Manager to recognize systemd-resolved as disabled
```Bash
vim /etc/NetworkManager/NetworkManager.conf
# And then change dns to default. ex:
# dns=default
```

3. Remove the old /etc/resolv.conf file
```Bash
rm /etc/resolv.conf
```

4. Restart Network Manager
```Bash
sudo systemctl restart NetworkManager
```

5. Use dnsmasq to add google's DNS server into /etc/resolv.conf since it can't be modified directly

```Bash
sudo vim /etc/dnsmasq.conf
# Add to the end of the file:
server=8.8.8.8
server=8.8.4.4
```