-
Notifications
You must be signed in to change notification settings - Fork 45
/
dnsproxy.sh
executable file
·54 lines (41 loc) · 1.76 KB
/
dnsproxy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
. $(cd ${0%/*};pwd;)/../common.sh
DIR=$(cd ${0%/*};pwd;)
cleanup() {
docker rm -f dns1 dns2 foo >/dev/null
docker network rm mynet >/dev/null
}
trap "cleanup; myexit" EXIT
# Note:
# /etc/resolv.conf of runq containers is written only once at container start.
# Therefore the IP address of the DNS proxy container must not change.
# /etc/resolv.conf must not contain a search option.
# build dnsmasq image
docker build -t dnsmasq -f $DIR/Dockerfile.dnsmasq .
#
# example Docker network with default network address
#
# create network
docker network create mynet
# start DNS proxy container with name (runc)
docker run --runtime runc --net mynet --cap-add=NET_ADMIN --restart unless-stopped --name dns1 -d dnsmasq
docker run --runtime runc --net mynet --cap-add=NET_ADMIN --restart unless-stopped --name dns2 -d dnsmasq
# start named runq container foo (daemon)
docker run --net mynet --name foo --runtime runq --rm -td alpine sh
# resolve foo's IP via DNS proxy
docker run --net mynet --runtime runq --rm -e RUNQ_DNS=dns1,dns2 alpine ping -c 3 foo
checkrc $? 0 "dnsproxy by name"
cleanup
#
# example Docker network with custom network address
#
# create network
docker network create --subnet=172.30.0.0/16 mynet
# start DNS proxy container with fixed IP (runc)
docker run --runtime runc --net mynet --cap-add=NET_ADMIN --ip 172.30.0.254 --name dns1 -d dnsmasq
docker run --runtime runc --net mynet --cap-add=NET_ADMIN --ip 172.30.0.253 --name dns2 -d dnsmasq
# start named runq container
docker run --net mynet --name foo --runtime runq --rm -td alpine sh
# resolve foo's IP via DNS proxy
docker run --net mynet --runtime runq --rm -e RUNQ_DNS=172.30.0.254,172.30.0.253 alpine ping -c 3 foo
checkrc $? 0 "dnsproxy by IP address"