docker 使用ipv6 nat

canoziia
2022-10-26 / 3 评论 / 577 阅读 / 正在检测是否收录...

ipv6 nat也是不得已而为之, 毕竟设备又不总是有固定的v6地址. 之前一段时间不需要用robbertkl/ipv6nat这个容器, 只需要改/etc/docker/daemon.json就行, 但是重启之后不知道为什么不行了, 所以还是用上吧

  1. 首先是/etc/docker/daemon.json

    {
     "default-runtime": "nvidia",
     "runtimes": {
         "nvidia": {
             "path": "nvidia-container-runtime",
             "runtimeArgs": []
         }
     },
     "ipv6": true,
     "fixed-cidr-v6": "fd00:aaaa:0000:0000::/64",
     "default-address-pools": [
         {"base": "172.17.0.0/16", "size": 24},
         {"base": "fd00:aaaa:0000:1::/64", "size": 80}
     ]
    }

    上面的nvidia-container-runtime部分可以忽略. 为什么这里的address-pools的size要设成/80而不是/64或者更大, 详见 https://github.com/moby/moby/issues/42801 , 是docker的bug, 否则会只能创建一个含ipv6的网络, 特别怪.

  2. 然后用 https://github.com/robbertkl/docker-ipv6nat 该仓库处理ipv6nat, 之前有一段时间我只进行第一步和第三步就能ping通v6地址, 这一步或许有些人不需要?
    可以用这个docker-compose.yml:

    version: '3'
    services:
     run:
         restart: always
         container_name: ipv6nat
         privileged: true
         network_mode: host
         volumes:
             - /var/run/docker.sock:/var/run/docker.sock:ro
             - /lib/modules:/lib/modules:ro
         image: robbertkl/ipv6nat
  3. 要加入到ipv6网络的容器配置

    version: "3"
    
    services:
     c1:
         image: xxx
         container_name: c1
         networks:
             - n1
     c2:
         image: xxx
         container_name: c2
         networks:
             - n1
    networks:
     n1:
         name: n1
         driver: bridge
         enable_ipv6: true
2

评论 (3)

取消
  1. 头像
    PhysicsGuy
    Windows 10 · Google Chrome

    Hello! I am preparing for International Physics Olympiad and I recently saw your website and used the Chinese Physics materials. They are very good. I wanted to know if you could send me the National Chinese Team Training Tests (国家集训队试题)? It will be really useful. I have already solved the CPhO problems and the questions from the 国家集训队试题 of the year 2013. I need the 国家集训队试题 after 2013.. Thank you!

    回复
    1. 头像
      canoziia 作者
      Windows 10 · Google Chrome
      @ PhysicsGuy

      Hello, you can contact me at zc@canoziia.cn.

      回复
      1. 头像
        PhysicsGuy
        Windows 10 · Google Chrome
        @ canoziia

        I have sent an email. Please check!
        Thank you!

        回复