log / wget unable resolve host in docker apline container
So, I’m facing an error when trying build docker image (I’m running docker command inside the WSL2). Inside Dockerfile it run command:
RUN wget -q -O ...
The wget commands return error "unable resolve hostname...". After some research it possibly because the invalid docker configuration network.
What happened when we run wget command is, wget attempts to resolve domain names to both IPv4 and IPv6 addresses. If the IPv6 network configuration is not correctly set up or is disabled on our Docker host (or within the Alpine container), wget may fail to use IPv6, causing the “unable to resolve host” error.
My solution is to use ‘-4’ option on wget command to force wget to use IPv4 avoiding problem related to IPv6.
The command became:
RUN wget -q -O -4 ...
There is also same problem I found in stackoverflow, and maybe it can be used as reference for proper problem handling
- dns - wget: unable to resolve host address ‘github.com’ inside alpine docker image - Stack Overflow
- Set DNS options during docker build - Stack Overflow Or this from ChatGPT-4 (not tested):
- Check Docker’s IPv6 Configuration:
- Inspect whether Docker daemon has IPv6 enabled. This can be configured in the Docker daemon settings (
/etc/docker/daemon.json):
- Inspect whether Docker daemon has IPv6 enabled. This can be configured in the Docker daemon settings (
{
"ipv6": true,
"fixed-cidr-v6": "2001:db8:1::/64"
}