Windows下的Docker主机网络容器服务访问 [英] Docker host network container service access under Windows

查看:564
本文介绍了Windows下的Docker主机网络容器服务访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

If I run docker container using the host network (--network host), for any services running in the container their exposed port can be directly accessed from host right?

我一直这样想,直到我在Windows下使用主机网络运行docker容器-

I always thought so until I'm running docker container using the host network under Windows --

  • ip a s eth0显示我的容器IP地址为192.168.65.3
  • route | awk '/^default/ { print $2 }'给出192.168.65.1
  • 但是,我的主机的IP为10.66.xx.xx
  • The ip a s eth0 shows that my container IP address is 192.168.65.3
  • The route | awk '/^default/ { print $2 }' gives 192.168.65.1
  • However, my host machine has an IP of 10.66.xx.xx

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

I.e., the container IP address and host IP are completely different. Unlike what the https://www.metricfire.com/blog/understanding-dockers-net-host-option/ says.

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

Anyway, if I'm running any services in the container, how to expose their port so that they can be directly accessed from host? (I thought with host network (--network host), you no longer need to map port from container to host)

thx

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不支持主机联网:

Host networking is not supported on Windows:

host网络驱动程序仅适用于Linux主机,而Mac的Docker桌面,Windows的Docker桌面或Windows Server的Docker EE不支持.

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-主机/

我建议尝试将-p选项设置为docker run,因为Windows支持该功能.

I would suggest trying the -p option to docker run, since that is supported on Windows.

或者,一个论坛用户建议,以桥接模式使用VirtualBox安装Linux,然后可以使用主机联网. YMMV.

Alternately, one forum user suggests using VirtualBox in bridged mode to install Linux, which can then use host networking. YMMV.

这篇关于Windows下的Docker主机网络容器服务访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆