Pihole is a popular web filtering program, often used to block advertising from sites that are known to host malicious content. It’s also an open source alternative to commercially available anti-virus software and free of charge. This guide will show you how to set up Pihole in a Docker container with the latest stable release of pihole installed.,
The “install pihole on docker” is a step-by-step tutorial on how to set up Pihole in a Docker container.
When you read an article on a website, you may be bombarded by pop-up adverts. How can you block all of those ads? Install Pi-hole Docker and use it as a network-wide ad filter to boost network speed.
You’ll learn how to set up and install Pi-hole in a Docker container to block advertisements and websites in this article. Isn’t it thrilling? Continue reading to find out more!
This will be a hands-on presentation in this course. If you want to follow along, make sure you have the following items on hand:
- Windows 10 has Docker installed (but any supported OS will work).
- A PC running Windows 10 — The Windows 10 OS Build 19042.1165 is used in this tutorial.
Using Docker to Create Two Persistent Volumes
You’ll need to establish a Docker volume to hold the Pi-hole application and DNS settings before you can set up Pi-hole in a Docker container.
How to Create (and Manage) Docker Volumes on Windows is a related article.
Run the following commands in PowerShell as an administrator to create two volumes (volume create) called pihole app and dns config for Docker. You may also alter the names to anything you like.
create pihole app using docker volume create dns config in a docker volume
Next, execute the following command to see whether the Docker volumes were created properly. This command shows all Docker volumes accessible on your computer.
Two freshly created volumes, pihole app and dns config, are seen below.
For the Pi-hole Configurations, I created two Docker Volumes.
Using Environment Variables to Run a Pi-hole Docker Container
Now that you have two persistent volumes, you can use Pi-basic hole’s Docker image to start a Docker container. But first, make a note of your current IP address.
To get your local IP address, use the command below. To execute the single Docker command correctly, you’ll need your local IP address.
To get the pihole/pihole basic image from Docker Hub, execute the command below. Replace the values as needed, using the table below as a guide. The function of each flag of the command is explained in the table below.
TZ=Asia/Manila -e -e docker run —name=pihole -e SERVERIP=HereIsYourIPAddress -v pihole app:/etc/pihole WEBPASSWORD=password -v dns config:/etc/dnsmasq.d -p 81:80 -p 53:53/tcp -p 53:53/udp p 81:80 -p 53:53/tcp -p 53:53/udp -v dns config:/etc/dnsmasq.d —restart=unless-stopped pihole/pihole
Flags of Command for Pi-hole Dockers
|Flags of Command||Definition|
|—name=pihole||Pihole is the name of a Docker container. If a container with the identical name already exists on your computer, an error will occur.|
|TZ=Asia/Manila -e||Time zone is a variable in the environment. This lesson utilized Asia/Manila as an example, but you may use any GitHub gist that has the similar structure.|
|WEBPASSWORD=password -e WEBPASSWORD=password||Sets the Pi-hole interface’s password.|
|-e SERVERIP=HereIsYourIPAddress||Set your Docker container’s IP address. You’ll come back to this later to make Pi-hole function.|
|pihole app:/etc/pihole -v pihole app:/etc/pihole||Mounts the volume pihole app and stores the Pi-hole files in the /etc/pihole subfolder.|
|-v dns config:/etc/dnsmasq.d -v dns config:/etc/dnsmasq.d -v dns||Mounts the dns config disk and uses the /etc/dnsmasq.d subfolder to store DNS settings as needed.|
|p 81:80 -p 53:53/tcp -p 53:53/udp p 81:80 -p 53:53/tcp -p 53:53/udp||Maps the host machine’s ports to the Docker container’s ports (port 81 in host machine maps to port 80 of Docker container)|
|—restart=unless-stopped||Sets a restart policy that ensures the Docker container is constantly restarted until the user directly stops it.|
|pihole/pihole||Uses the official pihole/pihole base image from Docker Hub in the docker run command.|
The command fetches the pihole/pihole basic image from Docker Hub, as seen below. Once the pihole/pihole image has been downloaded to your PC, the program will run automatically and follow the parameters you provide.
Pihole/pihole picture is being downloaded.
You’ll get an output similar to the one below after pulling the pihole/pihole base image, indicating that you can already run the Pi-hole dashboard from the container.
Observing the Pi-hole Docker Container in Action.
Using the Web Interface for the Pi-hole Dashboard
You may now visit the Pi-hole dashboard after the Docker container you constructed is up and running. The Pi-hole dashboard is a graphical interface that lets you choose which adverts to block using your own or community-maintained blacklists.
Because you already mapped port 81 of the host system to port 80 of the Docker container, go to http://localhost:81 in your browser. Your web browser will then transport you to the Pi-hole dashboard.
Change the port to visit the Pi-hole dashboard if you used a different port while performing the preceding docker operation. http://localhost:n, for example, where ‘n’ is the port number.
Now, log in to the Pi-hole dashboard with the password you set by running the docker command in the “Using Environment Variables to Run a Pi-hole Docker Container” section. For this tutorial, the password is “password” (without quotes).
Getting to the dashboard of the Pi-hole.
The Pi-hole container, as seen below, is not actively blocking advertising and is in standby mode, waiting for “queries” or ad requests to be evaluated.
The default page of the Pi-hole dashboard is being seen.
Using the DNS Server on the Host to point to the Pi-hole IP Address
How do you start blocking advertisements on your local machine after the Pi-hole server is up and running? You must instruct your local system to send all requests to the Pi-hole IP address and to block any adverts that satisfy the criteria. Continue reading to find out how!
1. Right-click on your network settings icon in the Windows system tray and choose Open Network & Internet Settings to see the list of all network adapters in your machine.
Accessing Network & Internet Settings
2. Next, right-click on your network adapter and choose Properties from the context menu. The settings window for your network adapter will appear.
Getting to the Network Adapter Properties
3. Click the Properties button after selecting Internet Protocol Version 4 (TCP/IPv4) from the list under the Networking tab.
IPv4 Properties may be accessed.
4. Make the following changes to the IPv4 properties:
- Choose an option. Set a static IP address using the following IP address. The host machine’s static IP address enables other devices to connect and utilize the adblocker. The router’s default gateway is determined by your ISP provider’s settings in your country.
- Select the option Use the following DNS server addresses option to configure your DNS server, and add a DNS server in the Preferred DNS server field. Input the Docker server IP address you set from the previous docker command under the “Using Environment Variables to Run a Pi-hole Docker Container” section.
- In the Alternate DNS server area, type 18.104.22.168 for Google server, and then click OK. In the event that the Pi-hole Docker container goes down for whatever reason, the secondary DNS server acts as a DNS server. You may provide a different value for the alternative DNS server.
IPv4 Properties Configuration
DNS Configuration for a Single Device
If you have a smartphone or other device connected to the same network, you may configure its DNS server to match the host’s IP address. A smartphone is linked to the same network in this lesson.
1. Select Manual from the smartphone’s wireless network settings and enter the host machine’s IP address. Alternative IP addresses may be be added in case Pi-hole fails.
Smartphones have different wireless network setup interfaces.
Setting up a DNS server on a smartphone
2. In your smartphone’s web browser, go to various websites with a lot of advertising.
For this case, the Daily Mail and the New York Times websites were accessed many times for a total of 5-10 minutes. The amount of prohibited adverts from the device is shown in the live browser admin on the Pi-hole dashboard, as seen below.
At the time of writing, the bar charts were a recent addition to Pi-current hole’s edition. Line charts are used in certain previous versions.
Docker Pi-hole in Action for 5-10 Minutes with Smartphone Usage
Using Router Settings to Enable Home Network-Wide Blocking
Instead of creating a DNS server on a single device, consider specifying DNS servers in your router’s settings for all devices. Using the IP address may or may not be possible, depending on your router.
The router did not provide access to change DNS servers or DHCP during this demonstration. Due to router limitations, home networking was not fully examined in this course.
You may be able to encode the DNS server IP in a sample admin page the same way you did in a single device. This demonstration makes use of a Prolink PRS1841U-v2 router that is locked to an ISP.
The DNS setup interface varies every router, but the options are similar to those shown below.
Setting the DNS settings on a router manually.
You may also deactivate the DHCP server on the router and instead use Pi-DHCP hole’s server. This is shown in further depth in an example debate in the Pi-hole forum.
How to Configure Cloudflare Dynamic DNS
Using the Pi-hole Dashboard to block websites
Pi-default hole’s installation blocks about 92,725 websites, but you may add more by using the Pi-hole maker’s blacklists and other lists given by Pi-hole supporters.
1. Save the websites you want to ban in a text file with a name you want. The file is called blocklist.txt in this case.
2. Copy the blocklist.txt file to the Docker container’s volume in a file called blacklist.txt using the docker command below. Keep the blacklist.txt file on the Docker volume for Pi-hole to automatically detect it.
How to Copy Files to Your Docker Container Using Docker cp
d70:/etc/pihole/blacklist.txt docker cp blocklist.txt
3. Finally, return to the Pi-hole administration dashboard. In the left panel, go to the Tools menu and then to the Update Gravity link. Finally, click Update to get a new list of URLs to block using Pi-hole.
After copying additional website blacklists to a text file, the Pi-hole UI displays Update Gravity.
The following is an example of a successful update.
Update Gravity Success is being shown.
Using the Console to Update the Website Blocklist
Rather of surfing the Pi-hole GUI, you could choose to enter console commands. If this is the case, you may use PowerShell to execute a docker command to restrict websites. Use the docker exec command to open an interactive terminal session with the pihole app Docker container, allowing you to perform commands.
/bin/bash docker exec -it pihole app
To update Pi-blacklist hole’s of URLs, enter a terminal session and perform the command below.
Run pihole -g on a regular basis to keep your ad blocker up to date.
Using community-maintained URL blacklists to block websites
Some URLs are committed to having their contributors update them on a regular basis, while others are not, therefore downloading a blacklist from an older list may not reflect the most recent changes.
Use Pi-Adlist hole’s block list group management tool. Click the Group Management adlists option in the left side of the Pi-hole dashboard, then click Add to choose the list of URLs you wish to add to Pi-hole.
Adding a Community-Maintained URL Blacklist to Pi-Block hole’s List
You learnt how to obtain a Pi-Hole Docker image, test an active listening Pi-hole web interface, and connect an external device to Pi-hole in this lesson. You’ve also learned how to ban advertising and websites, and you’ve seen the Pi-hole dashboard block them.
Why not use any host computer to restrict adverts to other connected devices in the same network with this knowledge?
“Pihole is a free software, open-source application that acts as a local DNS server. It can be installed on any computer running Linux or Windows.” Reference: docker pihole github.
Frequently Asked Questions
- linuxserver pihole
- pihole-unbound docker
- pihole docker ubuntu
- pihole docker/portainer
- pihole docker raspberry pi