Docker local environment custom local domains (hosts file?)
At work we use dnsmasq to pass requests to TLDs that end in .docker
to localhost. Here is how:
Requirements: homebrew and administration access
To forward .docker
TLDs, install & configure Dnsmasq
.
$ brew up && brew install dnsmasq$ sudo mkdir -p /etc/resolver$ echo 'nameserver 127.0.0.1' | sudo tee -a /etc/resolver/docker > /dev/null$ echo 'address=/docker/127.0.0.1' | tee -a /usr/local/etc/dnsmasq.d/docker-tld.conf > /dev/null$ sudo brew services start dnsmasq
Note: The resolver will start working after a reboot
Modify /usr/local/etc/dnsmasq.conf
...listen-address=127.0.0.1 ...conf-dir=/usr/local/etc/dnsmasq.d/,*.conf
Test the DNS server
$ dig test.docker @127.0.0.1; <<>> DiG 9.9.7-P3 <<>> test.docker @127.0.0.1;; global options: +cmd;; Got answer:;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 40401;; flags: qr aa rd ra ad; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0;; QUESTION SECTION:;test.docker. IN A;; ANSWER SECTION:test.docker. 0 IN A 127.0.0.1;; Query time: 0 msec;; SERVER: 127.0.0.1#53(127.0.0.1);; WHEN: Thu Feb 08 16:24:12 CET 2018;; MSG SIZE rcvd: 45
Test the configuration
; Make sure your DNS is still working.$ ping -c 1 www.google.comPING www.google.com (216.58.206.4): 56 data bytes64 bytes from 216.58.206.4: icmp_seq=0 ttl=53 time=26.789 ms--- www.google.com ping statistics ---1 packets transmitted, 1 packets received, 0.0% packet lossround-trip min/avg/max/stddev = 26.789/26.789/26.789/0.000 ms
Check that .docker TLDs are working
$ ping -c 1 test.docker PING test.docker (127.0.0.1): 56 data bytes
Source: Passing Curiosity