Подробно реши задачу
Создано: 12 апреля 2025 г.
Создано: 12 апреля 2025 г.
Below is a step-by-step guide on how you can set up Pi-hole in a Docker container on a Windows machine (using Docker Desktop). The goal is to have an easily replicable container with all data stored in a Docker volume for persistence.
We’ll store the Pi-hole data (configuration, logs, etc.) in a Docker volume to ensure persistence. You can create a named volume via the command line:
bashdocker volume create pihole_data
(You can choose any name you like for pihole_data
.)
docker-compose.yml
FileUsing docker-compose
is often the easiest way to set up and replicate containers. Create a file named docker-compose.yml
in a new directory (for example, C:\pihole\docker-compose.yml
). In this file, place the following contents:
yamlversion: "3" services: pihole: container_name: pihole image: pihole/pihole:latest # Replace "latest" with a specific Pi-hole version tag if you need a stable reference # DNS is usually best exposed on host network or bridged with a specific port. # For Windows, bridging is typical, but you can also use host networking if available. ports: - "53:53/tcp" - "53:53/udp" - "80:80/tcp" # optionally expose Pi-hole's DNS over IPv6 if you use it: # - "53:53/udp6" # - "53:53/tcp6" # - "80:80/tcp6" environment: TZ: "Etc/UTC" # Change to your local timezone, e.g. "America/Chicago" WEBPASSWORD: "changeme" # Admin portal password, set your own secure password DNSMASQ_USER: "root" # Recommended setting for some Docker-based Pi-hole setups # If you want upstream DNS servers, you can set them here, for example: # PIHOLE_DNS_: "8.8.8.8;8.8.4.4" volumes: - pihole_data:/etc/pihole - pihole_data:/etc/dnsmasq.d # Unless you have a conflict, recommended to run Pi-hole on your default network # or in 'bridge' mode. For Windows, 'bridge' is typical: network_mode: "bridge" restart: unless-stopped volumes: pihole_data: external: true # Use our previously created volume
image: pihole/pihole:latest
Uses the official Pi-hole Docker image.
ports
environment
TZ
: Set your timezone.WEBPASSWORD
: The Pi-hole admin dashboard password.DNSMASQ_USER
: It can help avoid permission issues within the container.PIHOLE_DNS_
: You can override the upstream DNS servers that Pi-hole uses.volumes
pihole_data
) to both /etc/pihole
and /etc/dnsmasq.d
. This ensures all Pi-hole configs and logs survive container recreation.restart: unless-stopped
From the directory containing the docker-compose.yml
file, run:
bashdocker-compose up -d
Docker Compose will:
pihole/pihole:latest
image if you don’t have it locally.pihole
.pihole_data
to the container.Use docker ps
to check that the Pi-hole container is up and running:
bashdocker ps
You should see a container named pihole
with status “Up.”
To view Pi-hole logs:
bashdocker logs pihole
You can confirm the initial setup, check for errors, and see that it’s working properly.
Open your browser and navigate to http://<your-docker-host-ip-or-name>/admin
.
http://127.0.0.1/admin
or http://localhost/admin
.WEBPASSWORD
you set in the docker-compose.yml
.To use Pi-hole as your DNS, you need to configure your local network or devices to use the Pi-hole container’s IP address as the DNS server.
bridge
mode).Using Host Networking
If you want to run Pi-hole in the host network mode on Windows, it can be trickier. Windows Docker Desktop primarily supports bridge
mode for networking. If you need host networking (for example, to avoid port conflicts or to have the container bind directly on the host’s IP), you might need a more advanced setup or a dedicated Linux VM.
IPv6 Support
For IPv6 environments, remember to map IPv6 ports and set up Pi-hole to respond on IPv6 addresses. This might require additional environment variables. In most home networks, Pi-hole usage over IPv4 is sufficient, unless you specifically need IPv6 DNS filtering.
Updating Pi-hole
To update Pi-hole to the latest image, you can:
bashdocker-compose pull docker-compose up -d
Your data remains in the named volume, so the container will pick up all your existing settings.
Whitelists/Blacklists/Customizations
Any changes you make via the web interface (blocklists, whitelist, etc.) will be stored in /etc/pihole
(which is in the Docker volume), preserving them across container re-deployments.
With the above setup:
pihole_data
named volume.docker-compose.yml
and running docker-compose up -d
on any machine with Docker installed. Just be sure to create or re-use the same named volume.That’s it! You now have a persistent Pi-hole instance running in a Docker container on Windows. If you ever need to remove and recreate the container, all your Pi-hole settings and logs will remain intact thanks to the Docker volume.