Alexander Zeitler

Alexander Zeitler

Accessing local domains in local dev environment from Android emulator

Published on Friday, September 18, 2020

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 and we have defined a domain ui in /etc/hosts.

# Host Database
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
## ui localhost
::1 localhost

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 http://ui to

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:

version: "3"

# More info at and
container_name: pihole
image: pihole/pihole:latest
- "53:53/tcp"
- "53:53/udp"
- "67:67/udp"
- "80:80/tcp"
- "443:443/tcp"
TZ: 'America/Chicago'
# WEBPASSWORD: 'set a secure password here or it will be random'
# Volumes store your data between container upgrades
- './etc-pihole/:/etc/pihole/'
- './etc-dnsmasq.d/:/etc/dnsmasq.d/'
# Recommended but not required (DHCP needs NET_ADMIN)
restart: unless-stopped

Given 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. 8080:

- "53:53/tcp"
- "53:53/udp"
- "67:67/udp"
- "8080:80/tcp"
- "443:443/tcp"

Next, we run docker-compose up -d.

Then we can browse to http://localhost:8080/admin.

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:

cd ~/Library/Android/sdk/emulator
emulator -list-avds

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

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?

What are your thoughts about "Accessing local domains in local dev environment from Android emulator"?
Drop me a line - I'm looking forward to your feedback!
Imprint | Privacy