Let's consider you're using local domains in development and want access them from Android virtual devices using the Android emulator? Here's how to solve this on macOS using "serverless" pihole.
Given our local IP is
192.168.0.87 and we have defined a domain
# Host Database
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
If you want to access
http://ui from an virtual Android device running in the Android emulator, you get this error in Chrome:
To make it work, we need a DNS server which knows how to resolve
An easy way is to run the popular pihole in a Docker container (hence "serverless" in my post title 😉).
Just grab the sample
docker-compose.yml from the Docker registry:
# More info at https://github.com/pi-hole/docker-pi-hole/ and https://docs.pi-hole.net/
# WEBPASSWORD: 'set a secure password here or it will be random'
# Volumes store your data between container upgrades
# Recommended but not required (DHCP needs NET_ADMIN)
http://ui runs on port
80, we need to change the port mapping for port
80 in the
docker-compose.yml to another port, e.g.
Next, we run
docker-compose up -d.
Then we can browse to
The Browser should show something like this:
After this, we can click "Login" from the sidebar and login using the password (how to obtain the password is described on the Docker registry page linked above).
Next we can select "Local DNS records" from the sidebar:
Then we add a new DNS entry for
ui with IP address
Now it's time to start our emulator again, this time from the command line, as this is the easiest way to pass the DNS server setting:
Your output will look like this:
Now we can start the emulator again and pass the pihole DNS server running on
./emulator -avd Pixel_XL_API_29 -dns-server 192.168.0.87
Pointing Chrome again to
http://ui inside the virtual device should result in something like this now:
To me, local DNS has never been that easy. How about you?