Подробно реши задачу

Создано: 12 апреля 2025 г.

Отвечено с использованием O1 Pro от Chat01

Вопрос

photo_2025-04-12_21-15-29.jpgphoto_2025-04-12_21-15-29.jpg

Подробно реши задачу

Мысль

Reasoned for 34 seconds

Ответ

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.


1. Prerequisites

  1. Docker Desktop: Make sure Docker Desktop is installed and running on your Windows machine.
  2. WSL 2 (Recommended): For best results, run Docker Desktop with the WSL 2 engine enabled (this is the default after recent updates). You can confirm under Docker Desktop settings:
    • Settings → General → “Use the WSL 2 based engine”

2. Create a New Docker Volume

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:

bash
docker volume create pihole_data

(You can choose any name you like for pihole_data.)

3. Prepare a docker-compose.yml File

Using 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:

yaml
version: "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

Compose File Explanation

  • image: pihole/pihole:latest
    Uses the official Pi-hole Docker image.

  • ports

    • Port 53 (UDP/TCP) is for DNS queries.
    • Port 80 (TCP) is for the Pi-hole admin dashboard.
    • (Optional) If you’re using IPv6, you might need to expose those as well.
  • 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

    • We attach a named volume (pihole_data) to both /etc/pihole and /etc/dnsmasq.d. This ensures all Pi-hole configs and logs survive container recreation.
  • restart: unless-stopped

    • Ensures the container restarts automatically on reboot or if it crashes.

4. Launch the Pi-hole Container

From the directory containing the docker-compose.yml file, run:

bash
docker-compose up -d

Docker Compose will:

  1. Pull the pihole/pihole:latest image if you don’t have it locally.
  2. Create and start the container named pihole.
  3. Attach the named volume pihole_data to the container.

5. Verify and Configure

Check Container Status

Use docker ps to check that the Pi-hole container is up and running:

bash
docker ps

You should see a container named pihole with status “Up.”

Check Logs

To view Pi-hole logs:

bash
docker logs pihole

You can confirm the initial setup, check for errors, and see that it’s working properly.

Access the Pi-hole Web Interface

Open your browser and navigate to http://<your-docker-host-ip-or-name>/admin.

  • If Docker is running on your local Windows machine, try http://127.0.0.1/admin or http://localhost/admin.
  • Log in using the WEBPASSWORD you set in the docker-compose.yml.

6. Point Your Devices to Pi-hole

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.

  • If your router supports custom DNS settings, point its primary DNS to your Pi-hole’s IP (which should be the Docker host IP if you used bridge mode).
  • Alternatively, you can manually configure each device (e.g., in the network settings on your phone or computer) to use the Pi-hole’s IP as the DNS server.

7. Advanced Configuration

  1. 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.

  2. 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.

  3. Updating Pi-hole
    To update Pi-hole to the latest image, you can:

    bash
    docker-compose pull docker-compose up -d

    Your data remains in the named volume, so the container will pick up all your existing settings.

  4. 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.


Final Thoughts

With the above setup:

  • Your Pi-hole data and configuration will persist in the pihole_data named volume.
  • You can replicate this easily by backing up your 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.

Поделиться этим Q&A