docker 0在docker-compose中联网

2nc8po8w  于 2023-03-17  发布在  Docker
关注(0)|答案(1)|浏览(185)

我有一个Docker网络的问题,考虑以下几点:

#docker network create --driver macvlan \
  --subnet=1.2.3.0/24 \
  --gateway=1.2.3.1 \
  -o parent=eth2 \
  untrust

# cat /opt/docker-compose.yml
version: "3.5"
services:
  foo:
    container_name: foo
    image: foo/foo-agent:latest
    networks:
      default:
        ipv4_address: 1.2.3.4

networks:
  default:
    external:
      name: untrust

# docker inspect foo

...
            "Networks": {
                "untrust": {
                    "IPAMConfig": {
                        "IPv4Address": "1.2.3.4"
                    },
                    "Links": null,
                    "Aliases": [
                        "8f8cd42eb471"
                    ],
                    "NetworkID": "a0720868f1c9178bf0ac4e104076a0c2a318acf93c885319a7a5599c52a15992",
                    "EndpointID": "bb73157ed0b2376a7b002787388de8d2bed03eaabd995684eb06a66303d47620",
                    "Gateway": "1.2.3.1",
                    "IPAddress": "1.2.3.4",
                    "IPPrefixLen": 24,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:d0:76:e1:65",
                    "DriverOpts": null
    ...

docker-compose中的默认驱动程序已经被macvlan驱动程序替换了。这是否意味着应用程序foo将不再能够访问docker 0桥?
我们正在dmz中部署一个应用程序,希望确保它只能监听eth 2。

c0vxltue

c0vxltue1#

docker-compose中的默认驱动程序已经被macvlan驱动程序替换了。这是否意味着应用程序foo将不再能够访问docker 0桥?

  • 当仅连接到一个网络时,macvlan“硬连线”到您的桥接接口,但是为了防止循环,您不能与Docker主机通信,只能与该网络中的其它容器通信
  • 具有“本机”实现(例如,一个具有ipv6和ipv4的接口,其中您需要将容器用作路由器(在示例中为.222)或将ipv4网关IP分配给您的主机端子接口,此处为“foobar”
  • v6网关应该是::1/NETMASK地址,此地址应该分配给您的主机端子接口,此处为“foobar”,这样就可以了(这样,您还可以在Docker容器中拥有非NAT的IPv6
#native macvlan access via child of eth42, docker network will be named ipv6
docker network create -d macvlan --gateway 192.168.123.222 --ip-range=192.168.123.128/25 --subnet=192.168.123.0/24 --aux-address='ip1=192.123.254.2' --aux-address='host=192.168.123.123' -o "com.docker.network.bridge.name=ipv6"  --ipv6 --subnet=2a01:d34d:beef::/48 --gateway 2a01:d34d:beef::1 -o macvlan_mode=bridge -o parent=eth42   ipv6
ifconfig eth42 up
ip link add foobar link eth42 type macvlan mode bridge
#ifconfig foobar
ifconfig foobar 192.168.123.222/24 up 
ip -6 a a 2a01:d34d:beef::1/48 dev foobar

相关问题