简体   繁体   English

如何更改 windows docker 容器中的主机文件

[英]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.

相关问题 如何将 DNS 条目添加到 Windows 容器的主机文件中? - How can I add DNS entries to hosts file of a Windows Container? 我可以为spring boot docker容器配置hosts文件吗? - Can I config the hosts file for spring boot docker container? Docker - Windows 容器无法解析主机 - Docker - Windows Container Not Resolving Hosts 禁用Docker容器中的主机文件 - Disable hosts file in docker container 使用 Spotify Maven Docker 插件,如何更改添加到 Docker 容器的资源的文件权限? - Using the Spotify Maven Docker plugin, how can I change the file permissions of a resource that I add to a Docker container? 我可以更改 Windows Docker 容器中的日期和时间吗? - Can I change the date and time in a Windows Docker Container? 无法更改Docker容器中的文件? - Can not change a file in docker container? 如何在 Windows 上运行 Windows Docker 容器而没有“打开 \\.\pipe\docker_engine_windows:系统找不到指定的文件”? - How can I run a Windows Docker container on Windows without "open \\.\pipe\docker_engine_windows: The system cannot find the file specified"? 如何让 Docker 容器使用主机的“/etc/hosts”文件? - How can you make the Docker container use the host machine's '/etc/hosts' file? 如何自动缩放 Docker 容器主机? - How to autoscale Docker container hosts?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM