Docker Could not resolve 'deb.debian.org'
Asked Answered
M

7

23

I was trying to build a container in Docker for some experiments. Here is my Dockerfile.

FROM debian

RUN mkdir -p /var/run/sshd

RUN apt-get update
RUN apt-get install -y openssh-server

RUN apt-get install -y sudo

RUN echo AddressFamily inet >> /etc/ssh/sshd_config

ARG username=Rivers
ARG userpasswd=perfectXJ2017

RUN useradd -ms /bin/bash $username && (echo $username:$userpasswd | chpasswd)

RUN adduser $username sudo

CMD /usr/sbin/sshd -D

I tried to build my image with the command sudo docker build -t ics-image ..

But then I got some error messages and the whole process stopped. Here is the error messages.

Sending build context to Docker daemon  2.048kB
Step 1/11 : FROM debian
 ---> 8626492fecd3
Step 2/11 : RUN mkdir -p /var/run/sshd
 ---> Running in 1e1f2dbbe5ca
Removing intermediate container 1e1f2dbbe5ca
 ---> dd4bec2f81d4
Step 3/11 : RUN apt-get update
 ---> Running in 022301215bfb
Get:1 http://security.debian.org/debian-security stretch/updates InRelease [94.3 kB]
Get:2 http://security.debian.org/debian-security stretch/updates/main amd64 Packages [450 kB]
Err:3 http://deb.debian.org/debian stretch InRelease
  Could not resolve 'deb.debian.org'
Err:4 http://deb.debian.org/debian stretch-updates InRelease
  Could not resolve 'deb.debian.org'
Fetched 544 kB in 20s (26.9 kB/s)
Reading package lists...
W: Failed to fetch http://deb.debian.org/debian/dists/stretch/InRelease  Could not resolve 'deb.debian.org'
W: Failed to fetch http://deb.debian.org/debian/dists/stretch-updates/InRelease  Could not resolve 'deb.debian.org'
W: Some index files failed to download. They have been ignored, or old ones used instead.
Removing intermediate container 022301215bfb
 ---> 054d32710b62
Step 4/11 : RUN apt-get install -y openssh-server
 ---> Running in 802d2fa37b8d
Reading package lists...
Building dependency tree...
Reading state information...
Package openssh-server 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 'openssh-server' has no installation candidate
The command '/bin/sh -c apt-get install -y openssh-server' returned a non-zero code: 100

I did all this on Ubuntu 18.04. I cannot understand why this happened and how to solve this problem. Can anyone help?

Mortification answered 26/6, 2018 at 2:36 Comment(0)
H
36

You should first check if you are able to resolve deb.debian.org from your host in which you are running docker. You can check that with nslookup deb.debian.org or dig deb.debian.org.

If you are not able to resolve the from host add nameserver 8.8.8.8 to your /etc/resolv.conf file and then try again. Docker copies nameservers from /etc/resolv.conf file.

Or you can set the nameserver by creating file /etc/docker/daemon.json

{
    "dns": ["8.8.8.8"]
}

then restart docker service:

$ service docker restart
Heimer answered 26/6, 2018 at 7:25 Comment(4)
This 100% solved this issue for me. Thanks for this!Shovelboard
Very nice thank you! Restarting the daemon after adding to the /etc/resolve.conf was required for me but not the daemon.json edit.Rabbinism
the nslookup is fine on my host. Adding dns in the deamon,json did not solve the issue for me.Incubate
Using nslookup, my host could resolve deb.debian.org, but I still had the issue while building my image with docker compose. However, I added the DNS setting anyways as a shot in the dark, and it works. You are a gift, my friend.Jonjona
T
30

This doesn't address the underlying issue, but I had success adding --network=host to the docker build command, e.g sudo docker build --network=host -t ics-image .. In my case everything in /etc/resolve.conf was correct, but there was an issue with docker using the correct ip tables and this was a quick workaround. Again, not a solution, but may help with debugging the problem.

Transcontinental answered 7/7, 2020 at 22:47 Comment(0)
H
6

This looks like your docker is not able to resolve the host properly. To check whether docker is able to resolve DNS, execute the below command. In some environments, network admins may block 8.8.8.8. If 8.8.8.8 is blocked use your local DNS IP.

sudo docker run busybox nslookup google.com

sudo docker run --dns 8.8.8.8 busybox nslookup google.com

If the first command doesn't work and second command works fine, then it shows it is a DNS resolution issue. Now edit the /etc/docker/daemon.json and add the DNS server IP that worked for you in the above command.

{
    "dns": ["8.8.8.8"]
}

Restart the docker service for the change to take effect using the below command.

service docker restart

Execute the below command to see your docker can now resolve DNS names.

sudo docker run busybox nslookup google.com
Harneen answered 3/9, 2019 at 23:6 Comment(1)
Could you please add the windows powershell equivalent commands?Bobbette
T
1

I was getting a permission error on the socket which prevented DNS from working. sudo apt-get purge --auto-remove apparmor from this article (https://forums.docker.com/t/can-not-stop-docker-container-permission-denied-error/41142/3) finally resolved it for me. Ubuntu - buster.

Tolmann answered 7/2, 2020 at 8:46 Comment(1)
Works, can you explain more details about the solution?Pedersen
A
0

I don't understand why but restarting the router actually helped me.

Alboin answered 22/9, 2022 at 11:37 Comment(0)
T
0

I was stuck in this two days. Somehow I can fix the problem with bellow solutions. It may help you.

$ sudo apt install traceroute $ sudo traceroute google.com

The result will be like this:

1 10.0.1.1 (10.0.1.1) 2.3 ms 2.6 ms 4 ms

2 <*.*.*.*>

3 <*.*.*.*>

So now you have your ip address in no 3.

Now First step

cp /etc/resolv.conf /etc/resolv.conf.orig

to copy this file in case you make an error.

And finally:

sudo nano /etc/resolv.conf

And you change your nameserver to the address you had with traceroute.

Your resolv.conf file will look like this:

#Generated by NetworkManager

nameserver 10.0.1.1

nameserver fec0::3<*.*.*.*>
Trypanosomiasis answered 7/5, 2023 at 8:45 Comment(0)
Q
0

You can change the settings in Docker Desktop under Settings/Docker Engine:

  ...
  "dns": [
    "8.8.8.8"
  ],
  ...
Qumran answered 1/8, 2024 at 10:31 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.