I have a Rails application that I want to deploy using Docker on an Ubuntu server. I have the Dockerfile for the application already set up, right now I want to view the nginx
conf in its container.
I ran the command below to start an nginx
container in an interactive mode:
docker run -i -t nginx:latest /bin/bash
Right now I am trying to install nano
editor in order to view the configuration for nginx
configuration (nginx.conf
) using the commands below:
apt-get update
apt-get install nano
export TERM=xterm
However, when I run the first command apt-get update
, I get the error below:
Err:1 http://security.debian.org/debian-security buster/updates InRelease
Temporary failure resolving 'security.debian.org'
Err:2 http://deb.debian.org/debian buster InRelease
Temporary failure resolving 'deb.debian.org'
Err:3 http://deb.debian.org/debian buster-updates InRelease
Temporary failure resolving 'deb.debian.org'
Reading package lists... Done
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.
I have checked very well it has nothing to do with network connectivity. I would need some help. Thank you.
17
Answers
Here's how I solved it:
Start the docker container for the application in an interactive mode, in my case it an
nginx
container :Run the command below to grant
read
permission to theothers
role for theresolv.conf
file:Note: If you are having this issue on your host machine (Ubuntu Linux OS) and not for the Docker containers, then run the same command adding
sudo
to it in the host machine terminal:Endeavour to exit your bash interactive terminal once you run this:
And then open a new bash interactive terminal and run the commands again:
Everything should work fine now.
Reference to this on Digital Ocean: Apt error: Temporary failure resolving 'deb.debian.org'
That's all.
I easily resolved it via:
Please also confirms /etc/sysctl.conf
sudo sysctl -p /etc/sysctl.conf
If you have VPN running, stop it and try again. It solved for me!
I had a similar issue, I tried many suggested solutions, but my issue was gone after I rebooted my VM.
Try restarting Docker.
sudo service docker restart
orsudo /etc/init.d/docker restart
For this to work, Docker should have been working fine in the past. If you never had Docker working in the first place, you probably have a different issue.
Under Debian, as root, I’ve ran:
This solved the issue for me.
Then build and run the container again.
Perhaps the network on the VM is not communicating with the default network created by docker during the build (bridge), so try "host" network :
for docker-compose:
I had the same problem and in my case it was file access control.
I uses extended acls on the docker root folder and did not realize it, because they where inherited from the folder above (stupid idea to test docker in a "scratch" directory where permissions are set via extended acls).
This lead to the situation that "/etc/resolv.conf" had setting "640" inside the running docker container with a "+" marking the extended acls. But the image did not have extended acls installed and could not handle it.
The weird thing was that, as far as I can see, all other network tools worked (e.g.
ping
) but onlyapt
could no access the DNS resolver.After removing the extended acls from the docker root and setting the usual acls, everything worked inside the running container.
Similar to the answer of "Promise Prestion", but solved permanently for new containers, too.
Specifying a DNS server for docker containers helped me.
Create a
/etc/docker/daemon.json
file with this content:and restart the docker service:
src: https://docs.docker.com/engine/install/linux-postinstall/#specify-dns-servers-for-docker
Similar issue, under debian.
Root cause was a bad DOCKER-USER rule in iptables chain
Those rules have been haded
so removing temporarily following rule fix the point
Coming here from some docker cross compiling headache:
While forking some repo I manually downloaded its
root
folder containingconfd
stuff and added it just like the original maintainer did.after this I was not able to
apt update
anymore.I found that the permission of my
root
named folder was wrong.stat -f "%OLp" root
revealed it is700
, but must be755
to work.and check flag of iptables, aslo add DNS if not added
then
solved me
Run this command:
echo -e "nameserver 8.8.8.8nnameserver 8.8.4.4" |sudo tee -a /etc/resolv.conf
After that run-
sudo apt-get update
This worked for me.
I was having the wrong DNS IP address in my /etc/docker/daemon.json. In my case, it was my home router DNS IP address and I was trying from the office network.
I found out my office DNS and updated with that.
I’m using Arch version 6.0.11 and docker version 20.10.21, and having this issues inside docker containers.
Thanks to @Marco, that was the initial hint to solve this. The problem is related to the use of extended ACLs in the host system.
The docker root folder has ACLs, you can see this as it has a plus sign at the end of permissions "+":
And what is the problem? Some docker images does not have ACLs installed, so as it was pointed this causes an issue.
Other network tools like curl resolved DNS properly, but
apt
orgit
have problems with DNS resolution.TLDR; Where is the fix? Modify ACL to set default rx to others.
After that, all network tools will be able to perform DNS resolution.
Credits:
Marco comment
Closed git issue in docker
The answer from @Mario Olivio Flores suggests using the
service
command. That is correct and probably works currently on all Linux distributions. However, as most Linux distributions prefersystemd
over systemV, it seems better to use just that with the following command:For example, on my Linux distribution the service script located at
/usr/sbin/service
just wrapssystemctl
, see this excerpt:For me, it turned out to be a random WSL 2 issue — running
wsl --shutdown
and restarting the containers solved it for me.