# Running Pi-Hole Network Wide Ad Blocker Using Docker

## What is Pi-Hole?

> The Pi-hole® is a DNS sinkhole that protects your devices from unwanted content, without installing any client-side software. -https://github.com/pi-hole/pi-hole

## Installing Docker

1. Log into the Linux based device
2. Run the following commands in the terminal
   # install prerequisites
   sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg-agent -y
   # add docker gpg key
   curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
   # add docker software repository
   sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
   # install docker
   sudo apt install docker-ce docker-compose containerd.io -y
   # enable and start docker service
   sudo systemctl enable docker && sudo systemctl start docker
   # add the current user to the docker group
   sudo usermod -aG docker $USER
   # reauthenticate for the new group membership to take effect
   su - $USER
   # edit resolvd config
   sudo nano /etc/systemd/resolved.conf
3. Uncomment the line starting with DNSStubListener= and set the value to no

   DNSStubListener=no

4. Press CTRL+O, Enter, CTRL+X to write the changes to resolved.conf
5. Continue with the following commands to restart systemd-resolve to free up port 53
   # restart the systemd-resolve service
   sudo systemctl restart systemd-resolved

## Running Pi-Hole

1. Now that Docker is installed, run the following commands to setup the Pi-Hole Docker container and run it
   # create working directories
   mkdir /home/$USER/docker/pihole -p && mkdir /home/$USER/docker/pihole/dnsmasq.d -p
   # run the pihole docker container
   docker run -d --name=pihole -e TZ=America/New_York -e WEBPASSWORD=password -v /home/$USER/docker/pihole/:/etc/pihole -v /home/$USER/docker/pihole/dnsmasq.d:/etc/dnsmasq.d -p 80:80 -p 53:53/tcp -p 53:53/udp --restart=unless-stopped pihole/pihole
2. Once the Pi-Hole container is downloaded and running, open a web browser and navigate to http://DNSorIP/admin

Documentation: https://github.com/pi-hole/docker-pi-hole