Pi-hole and Docker on MacOS to get rid of pesky advertising

  • August 21, 2019
  •  
  • August 23, 2019

When I’m at home I have setup a Raspberry Pi to run Pi-hole and block pesky advertising.

But. I am not always at home. I also bring my Macbook to work, customers, airports & hotels. I didn’t want to clutter up my system and install Pi-hole natively, so instead I used Docker

To make starting/stopping Pi-hole easier I created a small shell script:

#!/bin/bash
case "$1" in
    install)
        docker pull pihole/pihole
        exit 0
        ;;
    start)
        docker start pihole 2>&1 >/dev/null || docker run -d --name pihole -e WEBPASSWORD="Gloryhole" -e DNS1=1.1.1.1 -e DNS2=8.8.8.8 -p 53:53/tcp -p 53:53/udp -p 80:80/tcp -p 443:443/tcp pihole/pihole:latest 2>&1 >/dev/null
        networksetup -setdnsservers Wi-Fi 127.0.0.1 1.1.1.1 1.0.0.1 8.8.8.8 8.8.4.4
        echo "Started Pihole"
        exit 0
        ;;
    stop)
        docker stop pihole 2>&1 >/dev/null
        networksetup -setdnsservers Wi-Fi 1.1.1.1 1.0.0.1 8.8.8.8 8.8.4.4
        echo "Stopped Pihole"
        exit 0
        ;;  
    *)
        echo "Usage: $0 <install|start|stop>" >&2
        exit 1
        ;;
esac

More documentation on the Docker image can be found on GitHub: https://github.com/pi-hole/docker-pi-hole/#running-pi-hole-docker