首页 > 其他分享 >docker支持ipv6

docker支持ipv6

时间:2022-11-04 21:34:05浏览次数:74  
标签:-- 支持 db8 2001 64 ipv6 docker

方法

方法一、Pv6地址

不为容器中的服务特别分配IPv6地址。
只要Docker把外部的IPv6地址端口映射到容器的IPv4端口上,随后访问主机的IPv6相应端口即可。

方法二、为Docker网络分配IPv6地址

(1)Docker daemon默认只支持IPv4地址,通过在运行Docker时增加--ipv6参数可以使其同时支持ipv4和ipv6地址。
(2)此时容器仅获得了本地ipv6地址,如果要获得全局ipv6地址,必须确保机器有至少/80的地址段,通过在运行Docker时增加--fixed-cidr-v6参数为其配置ipv6子网。
该参数会在路由表中添加一条路由,相当于执行了一下命令:
$ ip -6 route add 2001:db8:1::/64 dev docker0
$ sysctl net.ipv6.conf.default.forwarding=1
$ sysctl net.ipv6.conf.all.forwarding=1
随后,所有路由往2001:db8:1::/64的流量都会通过docker0接口路由
(3)除了在运行时添加参数,还可以直接编辑/etc/docker/daemon.json文件,加入以下内容:
{
"ipv6": true,
"fixed-cidr-v6": "2001:db8:1::/64"
}
其中2001:db8:1::/64是IPv6地址段。

systemctl reload docker

(4)使用systemctl restart docker命令重启Docker。
(5)使用ifconfig命令查看分配到Docker网络的IPv6地址段
(6)完成了上面的配置之后,无需特意配置,只需正常建立容器,即可为容器分配IPv6地址。可以使用“docker inspect容器名”查看容器的IP地址。

官网教程

启用ipv6

Edit /etc/docker/daemon.json, set the ipv6 key to true and the fixed-cidr-v6 key to your IPv6 subnet. In this example we are setting it to 2001:db8:1::/64.

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

Save the file.
Reload the Docker configuration file.


$ systemctl reload docker

启用外部转发

https://docs.docker.com/netwo...

Enable forwarding from Docker containers to the outside world
By default, traffic from containers connected to the default bridge network is not forwarded to the outside world. To enable forwarding, you need to change two settings. These are not Docker commands and they affect the Docker host’s kernel.

Configure the Linux kernel to allow IP forwarding.

$ sysctl net.ipv4.conf.all.forwarding=1

Change the policy for the iptables FORWARD policy from DROP to ACCEPT.

$ sudo iptables -P FORWARD ACCEPT

These settings do not persist across a reboot, so you may need to add them to a start-up script.

创建自己的 ip6 网卡

开启ip6网卡后,只有 bridge 网卡,会自动启用 ip6

创建 user ip6 网卡

docker network create -d bridge --subnet 172.30.20.0/24 mynet2  --ipv6

docker network create -d bridge --ipv6 --subnet "fd00:daad:beee:1::/64" --gateway="fd00:daad:beee::1" --subnet=172.18.0.0/16 --gateway=172.18.0.1 myNet

# 需要仿照 bridge 的信息进行配置
docker inspect 37da
   {
      "Subnet": "2001:db8:1::/64",
      "Gateway": "2001:db8:1::1"
   }

docker network create -d bridge --ipv6 --subnet "2001:db8:2::/64" --gateway="2001:db8:2::1" --subnet=172.30.20.0/24 mynet2

绑定自己的容器到 自定义的网卡
docker run -d -p 30080:80 --net mynet2 nginx


$ sysctl net.ipv6.bindv6only = 1
$ sysctl net.ipv6.conf.default.forwarding=1
$ sysctl net.ipv6.conf.all.forwarding=1


docker network create -d bridge --ipv6 --subnet "2001:db8:3::/64" --gateway="2001:db8:3::1" --subnet=172.30.30.0/24 mynet3
docker run -d -p 30080:80 --net mynet3 nginx

如果需要 直接根据 ip 访问容器 需要 增加 路由配置

ip -6 route 查看路由中转

# 定向 2001:db8:1::/64 ip6 到 docker0 网卡设备
ip -6 route add 2001:db8:1::/64 dev docker0

暂停 删除所有

docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)

标签:--,支持,db8,2001,64,ipv6,docker
From: https://www.cnblogs.com/ltgybyb/p/16859183.html

相关文章

  • docker常用配置以及命令
    docker添加源windowslinux①.修改文件(没有则新增)touch/etc/docker/daemon.jsonvim/etc/docker/daemon.json添加代码Docker国内镜像源Docker中国区官方镜像:......
  • grafana jpprof jdk 8 支持探索
    问题运行问题java.lang.NoSuchMethodError:java.nio.ByteBuffer.flip()Ljava/nio/ByteBuffer;atjpprof.one.jfr.JfrReader.<init>(JfrReader.ja......
  • 基于 Docker 构建轻量级 CI 系统:Gitea 与 Woodpecker CI 集成
    WoodpeckerCI是一个由社区维护的DroneCI分支,使用ApacheLicense2.0许可证发布。社区版进一步扩展了pipeline的功能特性、支持对文件路径设置pipeline执行条件,并......
  • docker基本概念(一)
    docker官网和仓库地址docker官网:www.docker.com仓库hub.docker.comdocker能做什么提供系统平滑移植,容器虚拟化技术,软件带环境安装系统的快速扩容和缩容源码+配......
  • Docker容器中使用GPU
    背景容器封装了应用程序的依赖项,以提供可重复和可靠的应用程序和服务执行,而无需整个虚拟机的开销。如果您曾经花了一天的时间为一个科学或深度学习应用程序提供一个包含大......
  • Docker服务不能被外部访问的问题
    在DigitalOcean上边申请了一台Ubuntu的机器,安装了Docker,部署了服务。 当时监听的是127.0.0.1的80端口,访问的时候在VM上curl127.0.0.1是没有问题的。 不过通过......
  • docker常用命令
    1、问题描述docker使用越来越普遍,记录下,以便后续温故而知新;2、问题说明2.1什么是docker?docker的理解,看过很多,感觉这个是说的是最形象的。2.2docker安装2.2.1判......
  • Linux(Ubuntu、Centos)环境安装部署Docker及Docker-compose
    Centos7安装Docker环境#安装依赖yuminstall-yyum-utilsdevice-mapper-persistent-datalvm2#设置yum源(选择其中一个)yum-config-manager--add-repohttp://downl......
  • admin.net框架docker部署
    前端dockerrun-id-p81:80-v/root/docker/ioms/conf/nginx:/etc/nginx-v/root/docker/ioms/logs/:/var/log/nginx-v/root/docker/ioms/www/:/usr/share/nginx/ht......
  • java:compilation failed:internal java compiler error java-source 1.5中不支持 t
    具体参考:Error:java:Compilationfailed:internaljavacompilererror解决办法-程序猿的故事-CSDN博客1、查看项目的jdk(Ctrl+Alt+shift+S)File->ProjectStru......