无法为使用macvlan驱动程序的docker compose获取静态IP
我一直在尝试使用macvlan驱动程序使用静态IP配置一个盒子,但没有成功。我使用macvlan驱动程序是因为我想将它绑定到一个特定的接口,我认为使用网桥驱动程序是不可能的 当从另一个主机ping这个地址时,我只是超时了。这是预期的吗无法为使用macvlan驱动程序的docker compose获取静态IP,docker,docker-compose,Docker,Docker Compose,我一直在尝试使用macvlan驱动程序使用静态IP配置一个盒子,但没有成功。我使用macvlan驱动程序是因为我想将它绑定到一个特定的接口,我认为使用网桥驱动程序是不可能的 当从另一个主机ping这个地址时,我只是超时了。这是预期的吗 version: '3.4' services: test-box: image: nginx:latest networks: test-net: ipv4_address: 192.168.1.150 ne
version: '3.4'
services:
test-box:
image: nginx:latest
networks:
test-net:
ipv4_address: 192.168.1.150
networks:
test-net:
driver: macvlan
driver_opts:
parent: enp1s0f1.30
ipam:
config:
- subnet: 192.168.1.0/24
我还尝试了版本2的变体
version: '2.3'
services:
test-box:
image: nginx:latest
networks:
test-net:
ipv4_address: 192.168.1.150
networks:
test-net:
driver: macvlan
driver_opts:
parent: enp1s0f1.30
ipam:
config:
- subnet: 192.168.1.0/24
gateway: 192.168.1.1
ip_range: 192.168.1.0/24
我正在运行Ubuntu18.04LTS作为主机系统
注意:这是一个更复杂的docker compose文件的简化示例,我希望在其中运行多个框,每个框都有自己的IP,所有这些框都绑定到一个特定的接口。我需要配置静态IP,因为外部主机将需要使用其中一个容器。
docker run-p 10.20.30.40:80:888
将告诉docker启动一个容器,其中端口80位于特定IP地址10.20.30.40上,路由到容器中的端口8888。这是一种开箱即用的功能,不需要特殊的网络配置。您不需要macvlan或任何静态IP配置(您需要知道要绑定到的接口的主机IP地址)。NIC需要启用混杂模式
ifconfig eth1 up
ifconfig eth1 promisc
这不是问题所在。这是一个更复杂的docker compose文件的简化示例,我希望在其中运行多个框,每个框都有自己的IP,所有这些框都绑定到一个特定的接口。我需要配置静态IP,因为外部主机需要使用其中一个容器。