# Dockerコンテナネットワーク

**URL:** https://forum.ficusonline.com/t/topic/314
**Category:** Server
**Created:** [2019 年 8 月 6 日午前 7:52 UTC](https://forum.ficusonline.com/t/topic/314 "2019-08-06T07:52:49Z")
**Posts on this page:** 1
**Showing post:** 7

<div class="post-metadata">

### Author: ![tk-fuse](https://forum.ficusonline.com/user_avatar/forum.ficusonline.com/tk-fuse/32/255_2.png) [@tk-fuse](https://forum.ficusonline.com/u/tk-fuse)
#### Post date: [2023 年 2 月 11 日午後 2:03 UTC](https://forum.ficusonline.com/t/topic/314/7 "2023-02-11T14:03:49Z")

</div>

## コンテナIPv6サポート

> **[Use IPv6 networking](https://docs.docker.com/engine/daemon/ipv6/)**
>
> How to enable IPv6 support in the Docker daemon

[https://gdevillele.github.io/engine/userguide/networking/default\_network/ipv6/](https://gdevillele.github.io/engine/userguide/networking/default_network/ipv6/)

> **[Build a Docker IPv6 Network](https://dev.to/joeneville_/build-a-docker-ipv6-network-dfj)**
>
> 6️⃣ Docker supports IPv6 addressing and IPv6 network builds. 🔇 But IPv6 is not enabled by default. 🔊...

以下`IPv6`のサブネット（任意）を指定したデーモン設定ファイルを新規作成し再起動。

`/etc/docker/daemon.json`

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

```

**注）** `2001:db8:1::/64` はドキュメント内の例示として使用される予約されたIPアドレス

> **[List of reserved IP addresses](https://en.wikipedia.org/wiki/Reserved_IP_addresses)**
>
> Below is a list of reserved Internet Protocol (IP) addresses.
> In the Internet addressing architecture, the Internet Engineering Task Force (IETF) and the Internet Assigned Numbers Authority (IANA) have reserved various IP addresses for special purposes.
> IPv4 designates special usage or applications for various addresses or address blocks:

通常は以下のルール等を用いて作成 （LAN内プリフィックス：`FC00::/7`）

> [@IPv6, V6プラス(IPoE/IPv4 over IPv6)](https://forum.ficusonline.com/t/topic/466/2):
>
> IPv6アドレス Private network IPv6 RFC 4193 [RFC 4193: Unique Local IPv6 Unicast Addresses](https://www.rfc-editor.org/rfc/rfc4193#section-3) 3. Local IPv6 Unicast Addresses 3.1. Format The Local IPv6 addresses are created using a pseudo-randoml…

再起動

```auto
$ sudo systemctl restart docker

```

ブリッジモードの`IPv6`の有効化を確認  
**注）** ホストマシンにルータから`IPv6`アドレスが割当てられている場合

```auto
$ docker network inspect bridge
[
    {
        "Name": "bridge",
        ........
        ........
        "Driver": "bridge",
        "EnableIPv6": true,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.17.0.0/16",
                    "Gateway": "172.17.0.1"
                },
                {
                    "Subnet": "2001:db8:1::/64",
                    "Gateway": "2001:db8:1::1"
                }
            ]
        },
.....
.....

```

## IPv4, IPv6対応ブリッジネットワークの作成

> **[Build an IPv6 Network with Docker Compose](https://dev.to/joeneville_/build-an-ipv6-network-with-docker-compose-434i)**
>
> ✍️ In a previous post, I explained how to enable IPv6 for docker and build a network using the...

Docker Composerで使用する`IPv6`にも対応したカスタムブリッジネートワークを作成。

```auto
$ docker network create --gateway 172.20.0.1 --gateway 2001:db8:1:1::1 --subnet 172.20.0.0/24 --subnet 2001:db8:1:1::0/80 --ipv6 custom_network

```

**注）** ホストマシンのデフォルトのブリッジネットワークのサブネットを **`/64`** で割当てたので、カスタムブリッジネットワークに割当てるサブネットは、これより一段低い（16ビット分） **`/80`** とすること。

作成したネットワークの確認

```auto
$ docker network inspect custom_network
[
    {
        "Name": "custom_network",
        "Id": "912997c445af3a4718039d304c3b613aa0524659ca17bba5d87b5063a7ca795d",
        "Created": "2023-02-12T22:13:25.210491863+09:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": true,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "172.20.0.0/24",
                    "Gateway": "172.20.0.1"
                },
                {
                    "Subnet": "2001:db8:1:1::0/80",
                    "Gateway": "2001:db8:1:1::1"
                }
            ]
        },

```

**注）** コンテナに上記`IPv6`に対応したブリッジネットワークを使用する場合、ホスト側で`ip6tables(nftablesへ移行)`によるルールを追加する必要があります。

> **[\[SOLUTION\] Docker IPV6 and Docker compose woes](https://forums.docker.com/t/solution-docker-ipv6-and-docker-compose-woes/97852/4)**
>
> Why do you need the masquerade rule if you use a global ipv6 prefix? If your addresses aren’t routable and you need to use masquerade then why use global addresses instead of ULAs.

```auto
$ sudo ip6tables -t nat -A POSTROUTING -s 2001:3984:3989::/64 ! -o docker0 -j MASQUERADE

```

* * *

## IPv6アドレスの開放ポートの確認

> **[Is your site IPv6 ready?](https://ready.chair6.net/)**
>
> Test whether a web address, site, URL, or domain is IPv6 accessible. Tests for DNS AAAA records, IPv6-addressable nameservers, glue, IPv6 connectivity (port 80), and several other elements.

 ![Screenshot from 2023-02-12 22-18-22](https://forum.ficusonline.com/uploads/default/original/2X/5/5450ff4c1bbcd400fd35b04ea026cfed837faef7.png)

* * *

## DNS AAAAレコード(IPv6)確認

**`host`コマンド**

```auto
$ host -t AAAA google.com
google.com has IPv6 address 2a00:1450:4009:81d::200e

```

**`dig`コマンド**

```auto
$ dig google.com AAAA

; <<>> DiG 9.16.1-Ubuntu <<>> google.com AAAA
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 37561
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;google.com. IN	AAAA

;; ANSWER SECTION:
google.com. 101	IN	AAAA	2a00:1450:4009:823::200e

;; Query time: 3 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Mon Feb 13 12:18:19 UTC 2023
;; MSG SIZE rcvd: 67

```

---

_[View the full topic](https://forum.ficusonline.com/t/topic/314)._
