主机无法在 ipvlan l2 上 ping 通 docker 容器

问题描述 投票:0回答:0

我有一段时间一直在避免使用其他 Docker 网络类型,想要开始使用,所以遵循了一些教程。 Ipvlan l2 似乎在我见过或访问过的每个网站、视频或教程上都非常直观地工作。但我不明白我做错了什么。我有以下 docker-compose 文件。

networks:
    ipvlan:
        driver: ipvlan
        driver_opts:
            ipvlan_mode: l2
            parent: wlp3s0
        ipam:
            config:
                - gateway: 10.0.0.1
                  subnet: 10.0.0.0/24
services:
    www:
        image: test/nginx:latest
        networks:
            ipvlan:
                ipv4_address: 10.0.0.140
        # ports:
        #     - 80
        #     - 443

从容器内我可以 ping 通互联网和网关,但无法从主机 ping 通容器。由于它位于同一个子网中,所以我认为它可以开箱即用,无需创建任何链接、路由或地址...我知道我的需求更适合 l3 ipvlan,但在不知道发生了什么的情况下无法继续?

##### from host to container #####
$ ping 10.0.0.140
PING 10.0.0.140 (10.0.0.140) 56(84) bytes of data.
From 10.0.0.54 icmp_seq=1 Destination Host Unreachable
From 10.0.0.54 icmp_seq=2 Destination Host Unreachable
From 10.0.0.54 icmp_seq=3 Destination Host Unreachable
/ $ ping -c 4 10.0.0.1
PING 10.0.0.1 (10.0.0.1): 56 data bytes
64 bytes from 10.0.0.1: seq=0 ttl=42 time=9.459 ms
64 bytes from 10.0.0.1: seq=1 ttl=42 time=4.156 ms
64 bytes from 10.0.0.1: seq=2 ttl=42 time=2.373 ms
64 bytes from 10.0.0.1: seq=3 ttl=42 time=5.092 ms

--- 10.0.0.1 ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 2.373/5.270/9.459 ms
/ $ ping -c 4 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: seq=0 ttl=42 time=56.992 ms
64 bytes from 8.8.8.8: seq=1 ttl=42 time=57.372 ms
64 bytes from 8.8.8.8: seq=2 ttl=42 time=54.327 ms
64 bytes from 8.8.8.8: seq=3 ttl=42 time=55.030 ms

--- 8.8.8.8 ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 54.327/55.930/57.372 ms
docker networking ip subnet
© www.soinside.com 2019 - 2024. All rights reserved.