Move from Full Pihole to Docker

Hi All,

I've been using a full install of PiHole + DNSCrypt for a while and am looking to migrate this solution to Docker. Why - I'd like to learn how Docker works and maybe move to Kubernetes cluster.

Currently in the full version I have some modified and additional files sitting under /etc/pihole and /etc/dnsmasq.d/

I use a 03-custom-dns-names.conf file under /etc/dnsmasq.d/ which has my additional Conditional Reverse lookup names to the router and under /etc/pihole I have a modified custom.list file with the static name addressing of some of my systems.

For the life of me using docker-compose, I cannot see these files under respective folders under PiHole container? custom.list is there but with none of my values and 03-custom-dns-names.conf just does not get copied in? I've tried various methods:

volumes:                                                                                                                                                                                                                                                                                    etc-pihole:
    driver_opts:
      type: 'none'
      o: 'bind'
      device: '/opt/docker/etc-pihole'
  etc-dnsmasq.d:
    driver_opts:
      type: 'none'
      o: 'bind'
      device: '/opt/docker/etc-dnsmasq.d'

....
....

   volumes:
       - 'etc-pihole:/etc/pihole'
       - 'etc-dnsmasq.d:/etc/dnsmasq.d'

and also standard

  volumes:
       - './etc-pihole:/etc/pihole'
       - './etc-dnsmasq:/etc/dnsmasq.d'

I'm guessing these are not referenced in the Dockerfile during initial built?

Looking for some help adding the files to the Host and having them copied to the pihole container on up command?

Kind Regards

This isn't Pi-hole related - it is essentially a Docker question.

Exact location of Docker volume directories would depend on the Docker version and OS you are running on, as your Docker version would store Docker volumes in a specific folder of your host OS (e.g. /var/snap/docker/common/var-lib-docker/volumes/ when installing Docker via Ubuntu's snap).

As mentioned in Docker's documentation, you can then use e.g. docker inspect pihole and inspect the "Mounts" section to find out about file locations within Docker's file system, which would be relative to your host OS parent folder for Docker volumes.

For further details, please refer to Docker's documentation on volumes.

1 Like

I agree with @Bucking_Horn you need to do some research in the volumes and mounts. There are specifics depending on what platform you are running docker on. I have Docker on both a Synolgoy NAS and Raspberry Pi's and using this volume map which will leverage the directory where the .yaml file is located:

volumes:
   - './etc-pihole/:/etc/pihole/'
   - './etc-dnsmasq.d/:/etc/dnsmasq.d/'

When I check the directory etc-dnsmasq.d I find these files:

image

Hi Bucking_Horn, RonV42 -

I know it's a Docker issues - and maybe it needs to go else where, but for the life of me I cannot get it working like you RonV42 mentioned? I started a clean slate (maybe a permissions thing?).

System Information:

Docker version 20.10.12, build e91ed57
docker-compose version 1.29.2, build 5becea4c
Linux abc 5.10.0-11-amd64 #1 SMP Debian 5.10.92-1 (2022-01-18) x86_64 GNU/Linux
Debian 11.2

I create a folder /opt/docker/ with my docker-compose.yml file.

docker-compose.yml

version: "3"
                                                                                                                                                                                                                                                                                          services:                                                                                                                                                                                                                                                                                   pihole:
    container_name: pihole
    image: pihole/pihole:latest
    networks:
      pihole_net:
        ipv4_address: 172.16.255.3
    ports:
      - "53:53/tcp"
      - "53:53/udp"
      - "80:80/tcp"
      - "443:443/tcp"
    environment:
      TZ: 'Australia/Victoria'
      WEBPASSWORD: 'TopSecret'
      REV_SERVER: 'true'
      REV_SERVER_DOMAIN: 'mydomain.local'
      REV_SERVER_CIDR: '192.168.99.0/24'
      REV_SERVER_TARGET: '192.168.99.1'
    volumes:
       - './etc-pihole:/etc/pihole'
       - './etc-dnsmasq.d:/etc/dnsmasq.d'
    restart: unless-stopped
    dns:
      - 1.1.1.1

networks:
  pihole_net:
    driver: bridge
    ipam:
      config:
        - subnet: 172.16.255.0/24

The directories are created correctly in /opt/docker/ but adding files and re-creating the docker does not grab the new files or changes?

sudo docker inspect pihole/pihole

[
    {
        "Id": "sha256:ab22a9e4a99484de6c2be0ee699e0d88fab2fb7c557f17c63e3af0418c71a897",
        "RepoTags": [
            "pihole/pihole:latest"
        ],
        "RepoDigests": [
            "pihole/pihole@sha256:60a9127372b0f7bb4b5eb09bc95e2735eb7b237999acf4bb079eb14b0f14632e"
        ],
        "Parent": "",
        "Comment": "buildkit.dockerfile.v0",
        "Created": "2022-02-13T01:15:34.863856778Z",
        "Container": "",
        "ContainerConfig": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": null,
            "Cmd": null,
            "Image": "",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": null
        },
        "DockerVersion": "",
        "Author": "",
        "Config": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "53/tcp": {},
                "53/udp": {},
                "67/udp": {},
                "80/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/opt/pihole:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "phpver=php",
                "PIHOLE_DOCKER_TAG=2022.02.1",
                "S6_OVERLAY_VERSION=v2.1.0.2",
                "PIHOLE_INSTALL=/etc/.pihole/automated install/basic-install.sh",
                "PHP_ENV_CONFIG=/etc/lighttpd/conf-enabled/15-fastcgi-php.conf",
                "PHP_ERROR_LOG=/var/log/lighttpd/error.log",
                "IPv6=True",
                "S6_LOGGING=0",
                "S6_KEEP_ENV=1",
                "S6_BEHAVIOUR_IF_STAGE2_FAILS=2",
                "ServerIP=0.0.0.0",
                "FTL_CMD=no-daemon",
                "DNSMASQ_USER=pihole"
            ],
            "Cmd": null,
            "Healthcheck": {
                "Test": [
                    "CMD-SHELL",
                    "dig +short +norecurse +retry=0 @127.0.0.1 pi.hole || exit 1"
                ]
            },
            "Image": "",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": [
                "/s6-init"
            ],
            "OnBuild": null,
            "Labels": {
                "org.opencontainers.image.created": "2022-02-13T01:14:46.113Z",
                "org.opencontainers.image.description": "Pi-hole in a docker container",
                "org.opencontainers.image.licenses": "",
                "org.opencontainers.image.revision": "1b35e7fdd425ee2ac49b3aadc33ac1489c897ef3",
                "org.opencontainers.image.source": "https://github.com/pi-hole/docker-pi-hole",
                "org.opencontainers.image.title": "docker-pi-hole",
                "org.opencontainers.image.url": "https://github.com/pi-hole/docker-pi-hole",
                "org.opencontainers.image.version": "2022.02.1"
            },
            "Shell": [
                "/bin/bash",
                "-c"
            ]
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 298026137,
        "VirtualSize": 298026137,
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/a0a6f868b79c80181e2f9127041ba451387a5153f0eb441771fd4f790692b923/diff:/var/lib/docker/overlay2/490c3f89618868eda1c93a140d1c6c339946923ffac9ad3294b73f12331b05cb/diff:/var/lib/docker/overlay2/62d103748e9c0ca6367adae5355f876de8ddcc8868eaa2bbbe128ab01693f4f3/diff:/var/lib/docker/overlay2/b84d95143d85a6863b3c21b33fc17257a847ee4e8d3b43d38c09891c73a1309e/diff:/var/lib/docker/overlay2/96b9cfc1be3b71b3d3570ee3bcd37d5d0a093e0763a2e8a483870e31d3d1c94c/diff:/var/lib/docker/overlay2/8834f29092247db44795362e50ba70b3affe058ad84bcdbffa5562a144580634/diff:/var/lib/docker/overlay2/9cbf9cae6c3c2fe8f23062c7e5a57f266cb67b4c42fb4dcc2d4050a4e6205edf/diff:/var/lib/docker/overlay2/017fe95b4d58f45ef77f2042e519480ce39e30a13261b2ca80a93488b4338d25/diff",
                "MergedDir": "/var/lib/docker/overlay2/345cf9ffec9a44d7ca737201d61c71c4713441c185586c035e1601de869ec50f/merged",
                "UpperDir": "/var/lib/docker/overlay2/345cf9ffec9a44d7ca737201d61c71c4713441c185586c035e1601de869ec50f/diff",
                "WorkDir": "/var/lib/docker/overlay2/345cf9ffec9a44d7ca737201d61c71c4713441c185586c035e1601de869ec50f/work"
            },
            "Name": "overlay2"
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:f18b02b14138b6f9808f9843cc645e2edd64b02ca1c87e671355f56d1b4b5ec6",
                "sha256:74a6383525bf5c84975c831752f64bfe5249a977c2008a7472251aeb11bb8a25",
                "sha256:6786b1a5c1a478c6ff36b8980ab67854042c97dd5d69604835aa555ad4cfdb0c",
                "sha256:d3c990fc34ac1688d47033156c41182b826def002f38776083e4d5416e21dd50",
                "sha256:6ce96c5a9c5fc97dbc89da9fd4c3e6a01466f37b36e3149333c9b3c609eef639",
                "sha256:5413e37170ffd9ec39033ad9283b53a65be734d7e175051f2d7be5b4475b2348",
                "sha256:9ced693cf23d729fc9db51823b5c906aabb66935044194832564387b64b2b010",
                "sha256:8d9e63a1e22301137e3a059a89ea03a7fc07cdc7b64412abb6b29d4b41c5a780",
                "sha256:ee74dec9e1228fccce854a5fdf04b4a0e5b9d28024c7d112fcd4990222138384"
            ]
        },
        "Metadata": {
            "LastTagTime": "0001-01-01T00:00:00Z"
        }
    }
]

If I use mounts - they get mapped to
/var/lib/docker/volumes/docker_etc-dnsmasq.d/_data
/var/lib/docker/volumes/docker_etc-dnsmasq.d/_data

Still won't see my changes or added files? Weird.

Regards

Hi All,

Ignore me - looks like it is working, I am just new to Docker and have found that I'm spawning new instances and looking in the wrong container - aaggh!

Appreciate the help!

2 Likes

Just mark it down as a learning experience. Glad you got it to work.

I did however have a question about commands.

I did notice pihole runs a command /s6-init. If I wanted to run additional commands after this within the docker-compose - should adding the following work?

command:
      - /bin/bash
      - -c
      - |
        chmod +x /opt/script/enabledisable_domainlist.sh
        crontab /opt/script/cron.txt

I tried but container keeps restarting.

Cheers

That script isn't provided by Pi-hole. It doesn't exist in Pi-hole's image.

If you want to apply custom scripts to your Pi-hole installation, you'd have to stick with your bare metal Pi-hole.

Hi Bucking_Horn,

You are right these are custom scripts used to schedule blacklists on and off via cron.

Appreciate your help!

Hi Bucking_Horn,

Had some help from the guys over in the Docker Forum:

The trick was to add a script into /etc/cont-init.d (called deploycron.sh) that ran the following:

chmod +x /opt/script/enabledisable_domainlist.sh && crontab /opt/script/cron.txt

Then under the volume section in my yml, I had the following volumes.

 volumes:
      - './etc-pihole:/etc/pihole'
      - './etc-dnsmasq.d:/etc/dnsmasq.d'
      - './opt-script/:/opt/script'
      - './cron/deploycron.sh:/etc/cont-init.d/deploycron.sh'

This seems to have added the cron job into my container to enable and disable blacklists on a specific day.

Appreciate your help!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.