Last active
November 29, 2018 19:49
-
-
Save sashaaro/f787180be3594e5b3ccc8bd148a0eaec to your computer and use it in GitHub Desktop.
Access to docker containers via coredns and coredns-dockerdiscovery plugin for development env
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Install coredns | |
Build images with coredns & dockerdiscovery plugin | |
One way | |
git clone git@github.com:kevinjqiu/coredns-dockerdiscovery.git или go get github.com:kevinjqiu/coredns-dockerdiscovery.git | |
cd coredns-dockerdiscovery или cd ~/go/src/kevinjqiu/coredns-dockerdiscovery.git | |
docker build -t coredns-dockerdiscovery . | |
Create `Corefile` | |
skyeng.loc:53 { | |
docker unix:///var/run/docker.sock { | |
network_aliases skyeng_network | |
} | |
log | |
} | |
Start coredns with static assigned ip. For do it to indicate `--network` as any network for add ip | |
docker run -v /var/run/docker.sock:/var/run/docker.sock -v ${HOME}/Corefile:/coredns/Corefile --network skyeng_network --ip 172.19.5.5 --name=coredns --restart=unless-stopped -d coredns-dockerdiscovery -conf /coredns/Corefile | |
If you compiled binery file | |
docker run -v /var/run/docker.sock:/var/run/docker.sock -v ${PWD}/coredns:/coredns -v ${HOME}/Corefile:/Corefile --name=coredns --restart=unless-stopped --network=skyeng_network --ip=172.18.5.5 -d alpine /coredns | |
Check out | |
dig @172.19.5.5 postgres.e-api.skyeng.loc | |
Add our dns server's ip to system | |
echo "nameserver 172.19.5.5" | sudo tee --append /etc/resolvconf/resolv.conf.d/tail | |
sudo resolvconf -u | |
# possible you need install resolvconf (https://en.wikipedia.org/wiki/Resolvconf) | |
sudo apt install resolvconf | |
Check out | |
dig postgres.e-api.skyeng.loc | |
After manipulation with containers dns reply wrong ip | |
Sometimes it will be not avaliable or response contents not actual dns record. One of reasons is ttl not expired yet | |
You can cear resolve cache or reduce ttl | |
sudo systemd-resolve --flush-caches | |
Desirable reduce TTL by write cache directive in Corefile. | |
https://coredns.io/plugins/cache | |
Possible problems | |
Same topic https://github.com/jderusse/docker-dns-gen/issues/21 | |
Internal dns inside containers stop work well. | |
Solution | |
I fixed it by adding this { "dns": ["8.8.8.8", "8.8.4.4"] } in /etc/docker/daemon.json | |
systemctl restart docker | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment