[英]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.在我们的解决方案中,我们希望将 Edge 模块连接到不同网络上主机的服务总线。
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. dns 服务器不允许(根据设计)将 dns 映射到该主机,因此我需要在运行 Edge 模块的 Windows 容器的主机文件中执行 dns 映射。
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.我已经使用 docker 运行和 docker 构建命令进行了一些测试,设置了 --add-host 参数,但这似乎在 Windows 容器中不受支持。 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).此外,我不确定我是否可以使用它,因为 Edge 运行时控制着容器的运行(如果我在这里错了,请纠正我)。
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.
无论如何,这感觉像是一种 hack,而不是一个人应该做的。
Is there an easier way to add a dns host mapping?有没有更简单的方法来添加 dns 主机映射?
假设您正在使用Windows基本映像-您可以在那里修改hosts文件。
I did it with cmd, like this我是用 cmd 做的,像这样
docker exec --user "NT AUTHORITY\SYSTEM" -it <container> cmd
and when I got that shell I've run:当我得到 shell 时,我运行了:
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起初我试过 powershell 但我得到的只是文本之间的一些奇怪的空格
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.