Docker Windows 下的主机网络容器服务访问

Docker host network container service access under Windows

如果我 运行 docker 容器使用主机网络 (--network host),对于容器中的任何服务 运行,可以直接访问其暴露的端口主持人对吗?

我一直这么认为,直到我 运行ning docker 容器使用 Windows 下的主机网络 --

即容器IP地址和主机IP完全不同。与 https://www.metricfire.com/blog/understanding-dockers-net-host-option/ 所说的不同。

无论如何,如果我在容器中 运行ning 任何服务,如何公开它们的端口以便可以直接从主机访问它们? (我想到了主机网络(--network host),你不再需要将端口从容器映射到主机)

感谢

docker version
Client: Docker Engine - Community
 Version:           19.03.8
 API version:       1.40
 Go version:        go1.12.17
 Git commit:        afacb8b
 Built:             Wed Mar 11 01:23:10 2020
 OS/Arch:           windows/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.8
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.17
  Git commit:       afacb8b
  Built:            Wed Mar 11 01:29:16 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.2.13
  GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

Windows 不支持主机网络:

The host networking driver only works on Linux hosts, and is not supported on Docker Desktop for Mac, Docker Desktop for Windows, or Docker EE for Windows Server.

https://docs.docker.com/network/network-tutorial-host/

我建议尝试 docker run-p 选项,因为 Windows.

支持该选项

或者,一位论坛用户 suggests 在桥接模式下使用 VirtualBox 安装 Linux,然后可以使用主机网络。 YMMV.