'How can I add a host:ipv6-address mapping using 'docker build --add-host'

I need to add a host->ipv6 address mapping in the hosts file of my docker container. For IPv4 addresses I can simply use the -add-host option to 'docker build' but it seems this option does not accept IPv6 addresses? I have tried all sorts of formats:

--add-host somehost:2022:1:1:150::10
--add-host somehost:[2022:1:1:150::10]
--add-host somehost:\[2022:1:1:150::10\]

but it always gives the error 'invalid IP address in add-host: 2022:1:1:150::10'

it seems this is (yet another) area where docker's IPv6 support is lacking.

Does anyone have a solution to allow --add-host to work with an IPv6 address? or an alternative way of adding a host->IPv6 address mapping at image build time?

I am not using docker compose (and do not want to at this stage).

Thanks.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source