Docker build with alpine fails to run apk

Hi,

I’m running a docker build on an Ubuntu 16.04 system that is running on a VM at work. It’s failing when trying to run the apk commands because it gets an error:

ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.8/main: temporary error (try again later)

Is there a way to force the build to use IPv4 only addresses? If I run a wget using the same URL that the build is attempting to fetch it works fine, so I don’t think it’s a DNS issue or anything like that (I seem to be able to do lookups on the host without issue). So my only guess at the moment is that it’s trying to use the IPv6 address which then fails.

Thanks,

Rob

Hi,

So this appears to fail with Ubuntu as well. I have two Ubuntu VMs (16.04 and 18.04) on my Mac at home and when I do this on those VMs it works fine. I changed the RUN command in the Dockerfile to do a:

getent hosts dl-cdn.alpinelinux.org

Which, when I do it on the VMs on my Mac it works fine but it fails on the VM at work. So my guess is that DNS is failing. How would I specify an IPv4 DNS name server for docker to use?

Thanks,

Rob

If I create a container with a Dockerfile that just says:

FROM alpine

and do a build. If I then run the resultant container with:

% docker run --dns x.x.x.x -it XXXXX sh

Once inside the container I can do an ‘apk update’ just fine. So it’s clearly that ‘docker build’ is not using the correct name server. So I’m back to the question of: How do I define the IPv4 DNS name server address for docker build?

Thanks,

Rob

So I’m not exactly sure which changes are required, but I got it working. I uncommented and added the correct IP for the DNS server (this is on an Ubuntu 16.04 VM) in /etc/default/docker:

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

I created the file: /etc/docker/daemon.json and added:

{
    "dns":["x.x.x.x"]
}

And I modified /etc/init.d/docker and set:

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

I then restarted docker and it seems to be working.

Rob

The first two steps (setting DOCKER_OPTS in /etc/default/docker and creation of /etc/docker/daemon followed by a restart of the Docker daemon with sudo systemctl restart docker) solved the issue for me on Ubuntu 20.04.6 with Docker 24.0.5.