'How can I change the hosts file in windows docker container
In our solution we want to connect our Edge module to the servicebus of a host on a different network.
The dns server is not allowed (per design) to have the dns mapping to that host, hence I need to do the dns mapping in the hosts file of the Windows container that the Edge module is running in.
I have done some tests with the docker run and docker build commands, setting the --add-host parameter, but this doesn't seem to be supported in Windows containers. Looking at the file after the container has been started with that flag at least suggests that it is not.
Moreover I'm not sure I can use this since the Edge runtime is in control of the running of containers (please correct me if I'm wrong here).
In my desperation I tried to modify the hosts file through code, but got stopped due to administrative previledges not beeing met. Anyways this feels like a hack and is not what one should have to do.
Is there an easier way to add a dns host mapping?
Solution 1:[1]
Assuming that you are using a windows base image - you could modify the hosts file there.
Solution 2:[2]
I did it with cmd, like this
docker exec --user "NT AUTHORITY\SYSTEM" -it <container> cmd
and when I got that shell I've run:
echo x.y.z.w hostname >> c:\windows\system32\drivers\etc\hosts
at first i've tried with powershell but all I got was some weird blank spaces between my text
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | DougS |
Solution 2 | Gonzalo Rivero |