Local development domain

| 29.12.2016

I still see developers that manually edit their hostfile for every local project they run. Imho this is not required at all, and it's far easier to run a local dns caching server like dnsmasq, and use it to create a wildcard to a local development domain.

You can find many instructions on the internet how to set this up, below a summary for the setups we use:

For this post we'll use the domain `*.docker`.

Debian / Ubuntu

Code:

    sudo apt-get install dnsmasq
sudo echo "listen-address=127.0.0.1" >> /etc/dnsmasq.conf
sudo echo "address=/docker/127.0.0.1" >> /etc/dnsmasq.conf

Now add the line "prepend domain-name-servers 127.0.0.1;" to /etc/dhcp/client.conf and run `sudo service network-manager restart`.
There also should be a possibility to set `dns=dnsmasq` in the NetworkManager configuration, but this did not work on my debian install.

Mac OSX using Brew

Code:

    brew install dnsmasq
sudo echo "listen-address=127.0.0.1" >> /usr/local/etc/dnsmasq.conf
sudo echo "address=/docker/127.0.0.1" >> /usr/local/etc/dnsmasq.conf
sudo mkdir -p /etc/resolver
sudo echo "nameserver 127.0.0.1" > /etc/resolver/dev
sudo cp $(brew list dnsmasq | grep /homebrew.mxcl.dnsmasq.plist$) /Library/LaunchDaemons/
sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist

Mac OSX using MacPorts

Code:

    sudo port install dnsmasq
sudo echo "listen-address=127.0.0.1" >> /opt/local/etc/dnsmasq.conf
sudo echo "address=/docker/127.0.0.1" >> /opt/local/etc/dnsmasq.conf
sudo mkdir -p /etc/resolver
sudo echo "nameserver 127.0.0.1" > /etc/resolver/dev
sudo kill -9 $(pgrep dnsmasq)

You should now be good to go to have all *.docker domains pointing to 127.0.0.1.