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

{ 
	"ipv6": true,
	"fixed-cidr-v6": "2001:db8:1::/64"
}
Written on 2024-05-10 17:34:00 +0700 Edited on 2024-05-10 17:49:00 +0700