Skip to content

Pi-hole in Docker on a Synology NAS

UpdateDate
New guide released20/09/2021
Fixed a typo in the Environment Variables and added note around DHCP25/11/2021
Additional environment variable added to fix a start up error due to changes in the 2022.01 release and onward of PiHole.14/01/2022
Environment Variables updated to the latest requirements – Now runs as your locally created docker user rather than root07/04/2022


What is Pi-hole?

If you are looking to get advertising and tracking blocked across all the devices on your network a Pi-hole will have you covered. It’s a locally hosted Domain Name Server and uses block lists to stop adverts.

Lets Begin

Couple of things to note and common questions:

  • Pi-hole is not able to block YouTube ads
  • You will need to change the DNS settings either on your Router or whatever device is managing your DHCP/DNS settings
  • You will not be able to use this in conjunction with the DHCP server built into DSM if you have that enabled you will need to turn it off before continuing.

In order for you to successfully use this guide please complete the setting up a Docker user guide. Step 2: Setting up a restricted Docker user

Downloading the Pi-hole Image

Open up Docker within DSM and navigate to the ‘Registry’ section and search for ‘pihole’ in the search box. Download the official version.

The pop-up box will ask which version you want to download, make sure you choose ‘Latest’ from the list of available versions.

You can check the status of the download over on the ‘Image’ tab.

Setting up the container

In Docker click on the ‘Image’ tab, in the list of your containers select the ‘Pi-hole’ image and click on ‘Launch’

You will now see the initial setup screen, you can change the name of the container, we are not going to change the resource limitations.

Next up we are going to click on the ‘Advanced Settings’ button, this will take you to a new window with a number of tabs which we are going to work through.

On the first tab enable ‘Auto Restart’ this will ensure Pi-hole will automatically start up whenever you reboot your NAS.

Keep in mind if you turn off your Diskstation or stop the container you will lose internet access as there will be no way for devices to resolve DNS queries.

Volumes / Mounts

We can now move onto the volume tab in which we will be specifying the directories where Pi-hole will store its configuration files as per the table below.

File/FolderMount Path
/docker/pihole/dnsmasq.d/etc/dnsmasq.d
/docker/pihole/pihole/etc/pihole

We first click on ‘Add folder’ so we can create some folders for the config files to live, first create one called ‘pihole’ inside your /docker share

Then within that folder create two new folders called ‘dnsmasq.d’ and ‘pihole’

Now you have created these folders select ‘dnsmasq.d’ and then type or copy ‘/etc/dnsmasq.d’ into the mount path.

Then click add folder again and this time select the ‘pihole’ sub-folder you created and then type ‘/etc/pihole’ into the mount path

You show now be setup exactly as below

Network

We are not going to be specifying specific ports for Pi-hole to use as it needs to use standard DNS ports, so tick the ‘Use the same network as Docker host’ check box

You do not need to set up anything on these tabs.

Environment Variables

Next we are going to set up a some environment variables that docker will use to allow the container to access our local file system by telling it the IDs to use for file permissions

For each of the items in the table below you will need to click on ‘Add’ button then type each of the below in the ‘variable’ and ‘value’ sections.

variableValue
PIHOLE_UIDThe UID you obtained in the user setup guide
PIHOLE_GIDThe GID you obtained in the user setup guide
WEB_UIDThe UID you obtained in the user setup guide
WEB_GIDThe GID you obtained in the user setup guide
TZYour timezone wikipedia.org/wiki/List_of_tz_database_time_zones
WEBPASSWORDA password of your choice for the Pi-hole web interface
DNSMASQ_USERpihole
DNSMASQ_LISTENINGlocal
WEB_PORT8000

Once you have entered the above scroll down the Environment Variable as you will be able to see one called ServerIP you need to enter the IP address of your NAS e.g. 192.168.0.46

variableValue
ServerIPEnter the IP of you NAS

Almost done

You have now completed the container setup.

Click on the Apply button which will take you back to the screen we started at earlier, click on next, and you should see the Summary screen giving you the overview of the settings we changed.

Click on Done and the container should now start up, give it 30 seconds or so and you should then be able to access the Pi-hole web interface via you NAS IP followed by port 8000

e.g. 192.168.0.46:8000

You will now need to add the IP address of your NAS as your DNS address in your router or other DHCP server. It can take some time for all of your devices to move over the new DNS settings so be patient, and you will gradually start to see your stats begin to start.

Also note as we are not using Pi-hole as the DHCP server you will not be able to see the names of the devices in the statistics just their IP addresses.

That’s it!

Docker Compose

You can use the below code saved as pihole.yml in the ‘/docker/pihole’ share, this will do the entire process above in one quick command via SSH. Ensure you change the variables to your own. You will need to set up the correct sub-folders as per the section in the guide above.

version: "3.8"
services:
  pihole:
    image: pihole/pihole:latest
    container_name: pihole
    environment:
      - PIHOLE_UID=YOURUID
      - PIHOLE_GID=YOURGID
      - WEB_UID=YOURUID
      - WEB_GID=YOURGID
      - TZ=YOURTIMEZONE
      - WEBPASSWORD=YOURPASSWORD
      - DNSMASQ_LISTENING=local
      - WEB_PORT=8000
      - ServerIP=YOURNASIP
      - DNSMASQ_USER=pihole
    volumes:
      - /volume1/docker/pihole/dnsmasq.d:/etc/dnsmasq.d
      - /volume1/docker/pihole/pihole:/etc/pihole
    network_mode: host
    restart: unless-stopped
sudo docker-compose -f /volume1/docker/pihole/pihole.yml up -d


Throw me some bits or buy me a coffee?

If you have found my site useful please consider pinging me a tip as it helps cover the cost of running the site, you can even buy me a coffee 🙂

Buy Me A Coffee
Doge / Ethereum / Bitcoin
Published inDockerSynology

22 Comments

  1. Jan Jan

    Thank you so much! The hint with PIHOLE_UID, … has solved my permission problems <3

  2. Ross D Ross D

    Great tutorial.

    John Caruso’s comment re: DNSMASQ_USER=root fixed things for me.

    The :latest now seems to be working.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

drfrankenstein.co.uk – writing Synology Docker Guides since 2016 – Join My Discord!