如何使用 docker-compose 分配 IPv6 地址 [英] How to assign IPv6 address with docker-compose

查看:114
本文介绍了如何使用 docker-compose 分配 IPv6 地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Ubuntu 16.04 和 docker-compose 1.8.1 上使用 docker 1.12.1.我正在尝试从 https://docs 获取 Compose 文件.docker.com/compose/compose-file/#ipv4-address-ipv6-address 运行.作为参考,我使用以下内容创建了 docker-compose.yml:

I am using docker 1.12.1 on Ubuntu 16.04, and docker-compose 1.8.1. I am trying to get the Compose file from https://docs.docker.com/compose/compose-file/#ipv4-address-ipv6-address to run. For reference, I created docker-compose.yml with the following content:

version: '2'

services:
  app:
    image: busybox
    command: ifconfig
    networks:
      app_net:
        ipv4_address: 172.16.238.10
        ipv6_address: 2001:3984:3989::10

networks:
  app_net:
    driver: bridge
    driver_opts:
      com.docker.network.enable_ipv6: "true"
    ipam:
      driver: default
      config:
      - subnet: 172.16.238.0/24
        gateway: 172.16.238.1
      - subnet: 2001:3984:3989::/64
        gateway: 2001:3984:3989::1

现在,运行 docker-compose up 产生

Creating network "tmp_app_net" with driver "bridge"
Creating tmp_app_1
Attaching to tmp_app_1
app_1  | eth0      Link encap:Ethernet  HWaddr 02:42:AC:10:EE:0A  
app_1  |           inet addr:172.16.238.10  Bcast:0.0.0.0  Mask:255.255.255.0
app_1  |           inet6 addr: fe80::42:acff:fe10:ee0a/64 Scope:Link
app_1  |           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
app_1  |           RX packets:4 errors:0 dropped:0 overruns:0 frame:0
app_1  |           TX packets:1 errors:0 dropped:0 overruns:0 carrier:0
app_1  |           collisions:0 txqueuelen:0 
app_1  |           RX bytes:520 (520.0 B)  TX bytes:90 (90.0 B)
app_1  | 
app_1  | lo        Link encap:Local Loopback  
app_1  |           inet addr:127.0.0.1  Mask:255.0.0.0
app_1  |           inet6 addr: ::1/128 Scope:Host
app_1  |           UP LOOPBACK RUNNING  MTU:65536  Metric:1
app_1  |           RX packets:0 errors:0 dropped:0 overruns:0 frame:0
app_1  |           TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
app_1  |           collisions:0 txqueuelen:1 
app_1  |           RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
app_1  | 
tmp_app_1 exited with code 0

未分配 IPv6 地址.

The IPv6 address is not assigned.

我已经试过了:

  1. 使用 --ipv6 启动 docker 守护进程
  2. 使用 --ipv6 --fixed-cidr-v6="2001:3984:3989::/64" 启动 docker 守护进程
    • 请注意,docker run -it busybox ifconfig 实际上在这里给了我一个 IPv6 地址(来自分配给默认 --fixed-cidr 子网网桥网络)
  1. Starting the docker daemon with --ipv6
  2. Starting the docker daemon with --ipv6 --fixed-cidr-v6="2001:3984:3989::/64"
    • Note that docker run -it busybox ifconfig actually gives me an IPv6 address here (from the --fixed-cidr subnet which is assigned to the default bridge network)

没有成功.有什么想法吗?

No success. Any ideas?

推荐答案

事实证明这确实是一个 docker-compose 错误.

It turns out this is indeed a docker-compose bug that is going to be fixed in 1.9.0.

与此同时,有一种解决方法是使用 docker network 命令创建自定义网络:

Meanwhile, there is a workaround by creating a custom network with the docker network command:

docker network create --subnet=172.16.2.0/24 --gateway=172.16.2.1 --ipv6 --subnet=<myV6Network/subnet> dockerbridge

... 然后可以在 docker-composed.yml 中通过编写

... which can then be made available inside docker-composed.yml by writing

networks:
  dockerbridge:
    external:
      name: dockerbridge

这篇关于如何使用 docker-compose 分配 IPv6 地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆