如何在docker compose版本中启用IPv6:> = 3?

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

我需要为我的docker容器启用IPv4 / IPv6双栈支持。我的docker compose文件是版本3.默认情况下启用IPv4但是如何为docker container / network启用IPv6?

我已经尝试通过更新daemon.json来更新docker守护程序,并且我知道正在识别更新,因为如果文件中存在错误,Docker将无法启动。我在更改后重新启动了Docker(不仅仅是我的容器),但仍然没有容器的IPv6地址。

我发现docker compose文件中的enable_ipv6: true对版本3或更高版本无效,我不想按文件版本降级。

我更新的daemon.json:

{
  "ipv6": true,
  "fixed-cidr-v6": "2001:db8:1::/64"
}

当我检查我的容器时,在更改daemon.json之后,使用docker inspect {id}我看到以下内容:

"NetworkSettings": {
            "Bridge": "",
            "SandboxID": "df737362d15722fc1b0501ac256ba371417fe513dede807f2a17bd0524630a31",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "9000/tcp": null
            },
            "SandboxKey": "/var/run/docker/netns/df737362d157",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "healixportal_default": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": [
                        "php-fpm",
                        "9b8a7aee156b"
                    ],
                    "NetworkID": "5523ae0a4a936b47f212f0e301b64cbbad1f279a33107ed1f624e28d2df96c66",
                    "EndpointID": "880e13b64bec3fc84ae5a0abb5054bda66d5f439da6853f3538eb33be14b256b",
                    "Gateway": "172.18.0.1",
                    "IPAddress": "172.18.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:12:00:02",
                    "DriverOpts": null
                }
            }
        }

所以仍然没有为我的容器分配IPv6地址......

docker docker-compose ipv6 docker-networking
1个回答
1
投票

根据this issue的compose repo IPv6还不支持,但是有一种解决方法可能适合你:

你必须评论enable_ipv6: true,并保留所有其他参数,如文档所述。运行后:

$ sudo docker-comopose build

然后执行:

$ docker network create --driver bridge --ipv6 --subnet fd15:555::/64 --subnet 172.16.238.0/24 containerName-dockerfile_app_net --attachable

$ sudo docker-compose up -d

© www.soinside.com 2019 - 2024. All rights reserved.