[英]docker-compose macvlan can't access internet
I'm running ubuntu desktop in a virtual box (my host is mac), and inside this virtual machine I'm experimenting with macvlan
docker.network driver with docker-compose.我在一个虚拟盒子中运行 ubuntu 桌面(我的主机是 mac),在这个虚拟机中我正在试验
macvlan
docker.network 驱动程序和 docker-compose。
Here's my docker-compose.yml
file:这是我的
docker-compose.yml
文件:
version: '3.7'
services:
trader:
build: ./
image: giuliotrader
container_name: giuliotrader
networks:
trading:
ipv4_address: 172.16.86.33
depends_on:
- tws
tws:
build: ./ib-docker
image: ibconnect
container_name: ibconnect
ports:
- "4001:4001"
- "4003:4003"
- "5901:5901"
volumes:
- ./ib-docker/config.ini:/root/ibc/config.ini
- ./ib-docker/gatewaystart.sh:/opt/ibc/gatewaystart.sh
networks:
trading:
ipv4_address: 172.16.86.22
networks:
trading:
driver: macvlan
driver_opts:
parent: enp0s3.10
ipam:
config:
- subnet: 172.16.86.0/24
#gateway: 172.16.86.1
I'm having troubles with these two containers to access the inte.net.我在使用这两个容器访问 inte.net 时遇到了问题。
I can access the machines via docker exec -it ibconnect /bin/bash
, but there's no way they can access the.network, if I apt-get install iputils-ping
I get:我可以通过
docker exec -it ibconnect /bin/bash
访问机器,但是他们无法访问.network,如果我apt-get install iputils-ping
我得到:
Temporary failure resolving 'archive.ubuntu.com'
and if I nc -l 5047
on one container and nc 172.16.86.22 5047
on the other I get Connection refused
.如果我在一个容器上使用
nc -l 5047
,在另一个容器上使用nc 172.16.86.22 5047
,我会得到Connection refused
。
If I uncomment the last line ( gateway
) docker-compose reports an error:如果我取消注释最后一行 (
gateway
) docker-compose 报告错误:
ERROR: The Compose file './docker-compose.yml' is invalid because:
networks.trading.ipam.config value Additional properties are not allowed ('gateway' was unexpected),
I'm not sure what I'm missing in the configuration for configuring the gateway.我不确定在配置网关的配置中缺少什么。 How can I properly configure the.network in this setup?
如何在此设置中正确配置 the.network? I couldn't find any decent documentation.
我找不到任何像样的文档。
Thanks,谢谢,
I hit the same problem with MacBook Pro.我在 MacBook Pro 上遇到了同样的问题。 And the reason is probably a
macvlan
sub-interfaces were be blocked by wireless interface.原因可能是
macvlan
子接口被无线接口阻塞了。 When I connect LAN cable to the computer, and change VM's network adapter from en0: WiFi
to enX: USB 10/100/1000 LAN
, everything starts to work as expected.当我将 LAN 电缆连接到计算机,并将 VM 的网络适配器从
en0: WiFi
更改为enX: USB 10/100/1000 LAN
,一切都开始按预期工作。
The other solution is using ipvlan
instead of macvlan
.另一种解决方案是使用
ipvlan
而不是macvlan
。
My Setup:我的设置:
G
: 172.16.1.1/16 - Gateway(Physical) G
: 172.16.1.1/16 - 网关(物理)M
: 172.16.1.20/16 - Macbook Pro, [en0: Wifi(Physical), en7:LAN (Phsical)] M
: 172.16.1.20/16 - Macbook Pro, [en0: Wifi(Physical), en7:LAN (Phsical)]V
: 172.16.1.180/16 - Virtualbox + Ubuntu Server 20.04 [enp0s3 (Virtual)] V
: 172.16.1.180/16 - Virtualbox + Ubuntu Server 20.04 [enp0s3 (Virtual)]C1
: 172.16.180.53/16 - Docker container in home_macvlan
C1
: 172.16.180.53/16 - home_macvlan
Docker 容器C2
: 172.16.180.80/16 - Docker container in home_macvlan
C2
: 172.16.180.80/16 - home_macvlan
Docker 容器1- Set VM's network adapter en0:WiFi
as Bridged Adapter
, create macvlan
using docker in V
1- 将虚拟机的网络适配器
en0:WiFi
为Bridged Adapter
,在V
使用macvlan
创建macvlan
Status:地位:
M
<-> V
[OK] M
<-> V
[确定]
C1
<-> C2
[OK] C1
<-> C2
[确定]
V
<-> C1
[NOK] (As expected) V
<-> C1
[NOK](正如预期的那样)
M
<-> C1
[NOK] (The issue) M
<-> C1
[NOK](问题)
C1
<-> G
[NOK] (The issue) C1
<-> G
[NOK](问题)
ipvlan
instead of macvlan
ipvlan
而不是macvlan
en0:WiFi
as Bridged Adapter
en0:WiFi
为Bridged Adapter
ipvlan
using docker in V
V
使用ipvlan
创建ipvlan
The command that I run to create ipvlan
:我运行以创建
ipvlan
的命令:
docker network create -d ipvlan \
--subnet 172.16.0.0/16 \
-o ipvlan_mode=l2 -o parent=enp0s3 home_ipvlan
And then run the Docker container:然后运行 Docker 容器:
docker run \
--net=home_ipvlan \
--ip=172.16.180.53 \
--name=C1
<image name>
macvlan
on non 802.11 interface macvlan
enX: USB 10/100/1000 LAN
(Or other non 802.11 interface) as Bridged Adapter
enX: USB 10/100/1000 LAN
(或其他非 802.11 接口)设置为Bridged Adapter
PCnet-Fast III (Am79C973)
as Adapter TypePCnet-Fast III (Am79C973)
作为适配器类型 Command to create macvlan
创建
macvlan
命令
docker network create -d macvlan \
--subnet 172.16.0.0/16 \
--ip-range 172.16.180.0/24 \
--gateway 172.16.1.1 \
-o parent=enp0s3 home_macvlan
Command to run container:运行容器的命令:
docker run \
--net=home_macvlan \
--ip=172.16.180.53 \
--name=C1
<image name>
Related answer: https://stackoverflow.com/a/56918457/860189相关答案: https : //stackoverflow.com/a/56918457/860189
More info: https://hicu.be/macvlan-vs-ipvlan更多信息: https : //hicu.be/macvlan-vs-ipvlan
networks:
16-254:
driver: macvlan
driver_opts:
parent: ens192
macvlan_mode: bridge
ipam:
config:
- subnet: 172.16.16.0/24
gateway: 172.16.16.254
networks:
bridge:
driver: macvlan
driver_opts:
com.docker.network.enable_ipv4: "true"
parent: mac0
ipam:
config:
- subnet: xxx.xxx.xxx.xxx/xx
ip-range: xxx.xxx.xxx.xxx/xx
gateway: xxx.xxx.xxx.xxx
In the docke-host在码头主机中
ip link add mac0 link vmbr0 type macvlan mode bridge
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.