10

When run any apk add ... command while docker build ... I get DNS lookup error:

fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.8/main: DNS lookup error
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/community/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.8/community: DNS lookup error

How do I fix this?

zored
  • 2,718
  • 3
  • 19
  • 23

2 Answers2

10

It seems that my Dokcer inside of docker-machine had troubles resolving DNS.

I added this file /etc/docker/daemon.json into machine to make everything work correctly:

{
  "dns": ["8.8.8.8", "192.168.0.1"]
}

Also you may use docker run --dns 8.8.8.8 ... if you just run container.

zored
  • 2,718
  • 3
  • 19
  • 23
  • 1
    Worked for me, but I had to restart docker using "sudo service docker restart" – thowa Mar 21 '23 at 08:48
  • For minikube docker make sure you are updating in minikube server (`ssh minikube`) and restarting minikube docker (`sudo service docker restart`) – Naveen raj Apr 04 '23 at 18:10
1

Another way to fix it

edit /etc/init.d/docker

Update the following property

DOCKER_OPTS="--dns x.x.x.x"

Restart docker service

sudo service docker restart
boly38
  • 1,806
  • 24
  • 29