docker-compose macvlan无法访问互联网

问题描述 投票:2回答:1

[我在虚拟机中运行ubuntu桌面(我的主机是mac),在此虚拟机中,我正在尝试将macvlan docker网络驱动程序与docker-compose配合使用。

这是我的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

我在使用这两个容器访问互联网时遇到麻烦。

我可以通过docker exec -it ibconnect /bin/bash访问机器,但是如果我apt-get install iputils-ping可以得到,则它们无法访问网络:

   Temporary failure resolving 'archive.ubuntu.com'

并且如果我在一个容器上nc -l 5047而在另一个容器上nc 172.16.86.22 5047,则得到Connection refused

如果我取消注释最后一行(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), 

我不确定在配置网关的配置中缺少什么。如何在此设置中正确配置网络?我找不到任何合适的文档。

谢谢,

docker networking docker-compose docker-networking
1个回答
0
投票
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

在基座主机中

ip link add mac0 link vmbr0 type macvlan mode bridge
© www.soinside.com 2019 - 2024. All rights reserved.