読者です 読者をやめる 読者になる 読者になる

AKAI TSUKI

System development or Technical something

Try to use Docker DNS resolver.

Dockerコンテナに対してDNSを提供するコンテナですが、
以下のようなものがあるみたいです。
https://hub.docker.com/r/tonistiigi/dnsdock/
https://hub.docker.com/r/gliderlabs/resolvable/
他にもありそうですが。

gliderlabs/resolvableを試す。

docker pullします。(latestでない点に注意)

# docker pull gliderlabs/resolvable:master
master: Pulling from gliderlabs/resolvable
113f0a4e065f: Pull complete
a3ed95caeb02: Pull complete
d4bb54d8de9f: Pull complete
fb0214d7b5d4: Pull complete
5ca3576f73a4: Pull complete
3db7045e053c: Pull complete
Digest: sha256:c2b73bc355f61d832c1fe6dc3f14eed47a66c69934bb8ab5865ceb42aae8e7b3
Status: Downloaded newer image for gliderlabs/resolvable:master
#

イメージの確認

[root@node01 ~]# docker images
REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
centos                   latest              904d6c400333        12 days ago         196.7 MB
gliderlabs/resolvable    master              1f3be0ace382        3 months ago        254.7 MB
[root@node01 ~]#

Dockerホスト(CentOS 7)のresolv.conf

[root@node01 ~]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 8.8.8.8
[root@node01 ~]#
resolvable起動
[root@node01 ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[root@node01 ~]# docker run -d \
>   --name resolvable \
>   --hostname resolvable \
>   -v /var/run/docker.sock:/tmp/docker.sock \
>   -v /etc/resolv.conf:/tmp/resolv.conf \
>   gliderlabs/resolvable:master
38b46336d3464f40670de656d73a1a2de67acb07ce77a37ea0d02bb12dcc8f1d
[root@node01 ~]#
起動の確認
[root@node01 ~]# docker ps
CONTAINER ID        IMAGE                          COMMAND             CREATED             STATUS              PORTS               NAMES
38b46336d346        gliderlabs/resolvable:master   "/bin/resolvable"   3 minutes ago       Up 3 minutes                            resolvable
[root@node01 ~]#
[root@node01 ~]# cat /etc/resolv.conf
nameserver 172.17.0.2 # added by resolvable
# # Generated by NetworkManager
# nameserver 8.8.8.8
[root@node01 ~]#
コンテナを3つ起動
[root@node01 ~]# docker run -it --name test01 --hostname test01 centos bash
[root@test01 /]#
[root@node01 ~]# docker run -it --name test02 --hostname test02 centos bash
[root@test02 /]#
[root@node01 ~]# docker run -it --name test03 --hostname test03 centos bash
[root@test03 /]#
Ping実行!
[root@test01 /]# ping -c 3 test01
PING test01 (172.17.0.3) 56(84) bytes of data.
64 bytes from test01 (172.17.0.3): icmp_seq=1 ttl=64 time=0.018 ms
64 bytes from test01 (172.17.0.3): icmp_seq=2 ttl=64 time=0.061 ms
64 bytes from test01 (172.17.0.3): icmp_seq=3 ttl=64 time=0.061 ms

--- test01 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1999ms
rtt min/avg/max/mdev = 0.018/0.046/0.061/0.021 ms
[root@test01 /]# 

[root@test01 /]# ping -c 3 test02
PING test02 (172.17.0.4) 56(84) bytes of data.
64 bytes from test02 (172.17.0.4): icmp_seq=1 ttl=64 time=0.032 ms
64 bytes from test02 (172.17.0.4): icmp_seq=2 ttl=64 time=0.083 ms
64 bytes from test02 (172.17.0.4): icmp_seq=3 ttl=64 time=0.088 ms

--- test02 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 0.032/0.067/0.088/0.027 ms
[root@test01 /]# 

[root@test01 /]# ping -c 3 test03
PING test03 (172.17.0.5) 56(84) bytes of data.
64 bytes from test03 (172.17.0.5): icmp_seq=1 ttl=64 time=0.037 ms
64 bytes from test03 (172.17.0.5): icmp_seq=2 ttl=64 time=0.087 ms
64 bytes from test03 (172.17.0.5): icmp_seq=3 ttl=64 time=0.079 ms

--- test03 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 0.037/0.067/0.087/0.023 ms
[root@test01 /]#

test01のコンテナからtest02とtest03の名前で
各コンテナへの疎通が確認できました。