0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Docker の実験(その15:ブリッジネットワーク)

Last updated at Posted at 2023-02-20

その14:ネットワークの概要のつづき。

最初の一歩:vm (Container Optimized-os)への入り方(zone は環境による)

$ gcloud auth login
$ gcloud compute instances list
$ gcloud compute ssh --project <project-id> --zone asia-northeast1-b <vm-name>

次の一歩:コンテナへの入り方

$ docker ps
$ docker container exec -it <container id> bash

コンテナを調査して Network のところを確認する方法。

$ docker container inspect <container-name>

2つのコンテナを立ち上げて通信させてみる。

$ docker container run -dt --name bridge01 ubuntu
339b2fc35742c6f3717229ca48d084588e299eb7aa3f79da5e1302d9d0048cef
$ docker container run -dt --name bridge02 ubuntu
7777104893f7019fdac58c2e153f6418b99b6111d077d587af407dcacfa543b8

$ docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS                                   NAMES
7777104893f7   ubuntu    "/bin/bash"              30 seconds ago   Up 28 seconds                                           bridge02
339b2fc35742   ubuntu    "/bin/bash"              50 seconds ago   Up 48 seconds                                           bridge01
48f7a1225f89   ubuntu    "/bin/bash"              5 hours ago      Up 5 hours                                              myhost
8229282bc476   ubuntu    "/bin/bash"              28 hours ago     Up 28 hours                                             my_ubuntu
e6e93cd9f5c5   5e4       "nginx -g 'daemon of…"   2 days ago       Up 28 hours     0.0.0.0:8082->80/tcp, :::8082->80/tcp   mycustomnginx
67df4d402280   nginx     "/docker-entrypoint.…"   4 days ago       Up 2 days       0.0.0.0:8080->80/tcp, :::8080->80/tcp   mynginx

1台目のコンテナにログインしてみる。

$ docker container exec -it bridge01 bash
/# apt-get update && apt-get install net-tools && apt-get install iputils-ping
/# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1460
        inet 172.17.0.5  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:ac:11:00:05  txqueuelen 0  (Ethernet)
        RX packets 2607  bytes 26300516 (26.3 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2457  bytes 167530 (167.5 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
/# exit

2台目のコンテナにログインしてみる。

$ docker container exec -it bridge02 bash
/# apt-get update && apt-get install net-tools && apt-get install iputils-ping
/# ifconfig

2台目のコンテナから1台目のコンテナに ping してみる。

/# ping 172.17.0.5
ING 172.17.0.5 (172.17.0.5) 56(84) bytes of data.
64 bytes from 172.17.0.5: icmp_seq=1 ttl=64 time=0.105 ms
64 bytes from 172.17.0.5: icmp_seq=2 ttl=64 time=0.074 ms
64 bytes from 172.17.0.5: icmp_seq=3 ttl=64 time=0.067 ms
64 bytes from 172.17.0.5: icmp_seq=4 ttl=64 time=0.091 ms
64 bytes from 172.17.0.5: icmp_seq=5 ttl=64 time=0.087 ms

--- 172.17.0.5 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 

route table を確認する。

/# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.17.0.1      0.0.0.0         UG    0      0        0 eth0
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 eth0

引き続き、Google Cloud の Container optimized-os の Docker マシンで、以下のコマンドを確認する。
Container Optimized-os では、この、toolbox と言うコマンドを実行することにより、apt-get コマンドが使えて、パッケージがインストールできる。

$ toolbox
/# apt-get install bridge-utils
/# brctl showbridge name     bridge id               STP enabled     interfaces
docker0         8000.02423d1ff74d       no              veth48a4c4e
                                                        veth9636e80
                                                        vethc072a2f
                                                        vethdedb2be
                                                        vethf7d8ca0

引き続き、Google Cloud の Container optimized-os の Docker マシンで、以下のコマンドを確認する。

$ docker network inspect bridge
[
    {
        "Name": "bridge",
        "Id": "5e9118fc9ae3388d7311ad99eeec9140a5386381194d378941af2c39bbf8812f",
        "Created": "2023-02-18T12:13:31.170443126Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.17.0.0/16",
                    "Gateway": "172.17.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "339b2fc35742c6f3717229ca48d084588e299eb7aa3f79da5e1302d9d0048cef": {
                "Name": "bridge01",
                "EndpointID": "54a7e979505a2d8b08d56e7607dcf71013951f8ff356b62c4e9dbeb045f5862e",
                "MacAddress": "02:42:ac:11:00:05",
                "IPv4Address": "172.17.0.5/16",
                "IPv6Address": ""
            },
            "67df4d40228057e55850e67d3e9a3bff7ce51fc2a4bfcbefc6ba9b1dbd402942": {
                "Name": "mynginx",
                "EndpointID": "6595b6b7b116d05d442e73221424e520156427025452a46c32d32b4882799d42",
                "MacAddress": "02:42:ac:11:00:02",
                "IPv4Address": "172.17.0.2/16",
                "IPv6Address": ""
            },
            "7777104893f7019fdac58c2e153f6418b99b6111d077d587af407dcacfa543b8": {
                "Name": "bridge02",
                "EndpointID": "75b5a1435e20d95cffd7d00bb063dbbc1a18ff212279208d5130722e4585aacd",
                "MacAddress": "02:42:ac:11:00:06",
                "IPv4Address": "172.17.0.6/16",
                "IPv6Address": ""
            },
            "8229282bc476d6394eee8ad64ff9e9a40a3c678f6fef1ab060c21824c61514a0": {
                "Name": "my_ubuntu",
                "EndpointID": "3e094e4ff87e80616c80d1c14798108bfc65ea52c76ed3a670867d1ea36d6633",
                "MacAddress": "02:42:ac:11:00:04",
                "IPv4Address": "172.17.0.4/16",
                "IPv6Address": ""
            },
            "e6e93cd9f5c5f5b3bc68e5e6fd068d5eb49585d53d46190249e8b141f1408664": {
                "Name": "mycustomnginx",
                "EndpointID": "065ba8c9c8c0157b60fec5af2a301f6d069c898a1e1ea8d1a48c71c17747c1bf",
                "MacAddress": "02:42:ac:11:00:03",
                "IPv4Address": "172.17.0.3/16",
                "IPv6Address": ""
            }
        },
        "Options": {
            "com.docker.network.bridge.default_bridge": "true",
            "com.docker.network.bridge.enable_icc": "true",
            "com.docker.network.bridge.enable_ip_masquerade": "true",
            "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
            "com.docker.network.bridge.name": "docker0",
            "com.docker.network.driver.mtu": "1460"
        },
        "Labels": {}
    }
]

その16:ユーザー定義のブリッジネットワークとレガシーなリンクの方法につづく。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?