我需要从windows主机上的容器访问物理设备(运行Docker桌面)。该设备在一个单独的子网中有一个固定的ip地址(192.168.0.5/24)。如何正确设置容器的网络(通过docker run或docker-compose)?
我第一次想到只是打开相关的端口,但其中一个是随机选择的(e.h。52714,63575),第二,如果端口是打开的,我无法到达设备。因此,我试图获取一个伊夫兰,但是在这个配置中,我根本没有到达容器。
version: "3.8"
services:
python-fastapi:
container_name: fast_api
build:
context: Python
dockerfile: Vision_fastAPI.Dockerfile
ports:
- "5001:5000"
networks:
- myVLan
networks:
myVLan:
driver: ipvlan
driver_opts:
parent: host
ipvlan_mode: l2
ipam:
config:
- subnet: 192.168.0.0/24实际上,我试图复制一个教程(来自Ubuntu主机):
docker network create -d ipvlan --subnet=192.168.0.0/24 --ip-range=192.168.0.0/24 -o ipvlan_mode=l2 -o parent=enp11s0f1 myVLan显然,我很难接受parent选项。我想,我应该是物理以太网适配器,但我不知道窗口中的命名(docker-compose不接受像“以太网8”这样的名称,所以我想,我在这里出了点问题。)它适用于码头网络(“默认”),但不会产生错误。
以太网适配器的配置如下:
Ethernet adapter Ethernet 8:
Connection-specific DNS Suffix:
Description . . . . . . . . . . . : Lenovo USB Ethernet #4
Physical Address . . . . . . . . : 3C-18-A0-52-43-C1
DHCP Enabled . . . . . . . . . . : no
Autoconfiguration Enabled . . . . : Yes
IPv4 Address . . . . . . . . . . : 192.168.0.210(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :
NetBIOS over Tcpip . . . . . . . : Enabled发布于 2022-09-16 11:11:39
绝对什么都不做。删除撰写文件中的所有networks:块。以正常方式连接到外部IP地址;Docker提供网络地址转换(NAT)机制,使您能够连接到开箱服务。
如果为您的环境设置了域名服务(DNS)服务器(强烈推荐),请确保在连接到服务other-host.example.com时使用完全限定的域名(FQDN)。如果使用短名称other-host,那么Docker将尝试将其解释为容器名称。
https://stackoverflow.com/questions/73742328
复制相似问题