apk return DNS lookup error on docker build

Viewed 7769

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?

2 Answers

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.

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
Related