Is there any other reason you shut it down? Do you power off the whole server?
Those changes will be gone when you start the container again. What commands are you using to shut down the docker container and what commands are you using to start it again? If you are just restarting the existing container then your changes would stay until you had to change the image.
I guess you could volume mount just the /etc/cron.d/pihole file to persist any changes?
Yes I put the server to sleep since it's a full PC. I don't shut the docker down so it just resumes after waking up. My only concern is that the settings would not persist after updating the container.
Oh I can mount a file? I tried to mount /etc/cron.d folder before but it failed to boot. I'll try to mount the /etc/cron.d/pihole file tomorrow
You will also find that shutting the device down at midnight interferes with log rotations that happen at midnight. Consider shutting the device down 10-15 minutes later.
I tried to volume mount the /etc/cron.d/pihole file to persist it, but I get this error from docker-compose. Does this mean that /etc/cron.d/pihole is not yet created when it tries to mount it?
Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/run/desktop/mnt/host/e/Docker_pihole/etc-cron.d" to rootfs at "/etc/cron.d/pihole": mount /run/desktop/mnt/host/e/Docker_pihole/etc-cron.d:/etc/cron.d/pihole (via /proc/self/fd/14), flags: 0x5000: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
I deleted the compose for my previous post. But I tried it again with this:
version: "3"
# More info at https://github.com/pi-hole/docker-pi-hole/ and https://docs.pi-hole.net/
services:
pihole:
container_name: pihole
image: pihole/pihole:latest
# For DHCP it is recommended to remove these ports and instead add: network_mode: "host"
ports:
- "53:53/tcp"
- "53:53/udp"
#- "67:67/udp" # Only required if you are using Pi-hole as your DHCP server
- "80:80/tcp"
environment:
TZ: 'Asia/Manila'
WEBPASSWORD: 'passes1'
# Volumes store your data between container upgrades
volumes:
- './etc-pihole:/etc/pihole'
- './etc-dnsmasq.d:/etc/dnsmasq.d'
- './etc-cron.d/pihole:/etc/cron.d/pihole'
# https://github.com/pi-hole/docker-pi-hole#note-on-capabilities
#cap_add:
#- NET_ADMIN # Required if you are using Pi-hole as your DHCP server, else not needed
restart: unless-stopped
And the error is:
[+] Running 0/1
- Container pihole Starting 2.6s
Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/run/desktop/mnt/host/e/Docker_pihole/etc-cron.d/pihole" to rootfs at "/etc/cron.d/pihole": mount /run/desktop/mnt/host/e/Docker_pihole/etc-cron.d/pihole:/etc/cron.d/pihole (via /proc/self/fd/14), flags: 0x5000: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
I am on Windows but when I checked the docker location, docker created a pihole directory instead of a file. Maybe because /etc/cron.d/pihole has no extension?
I think I understand now. So I have to create the /etc/cron.d/pihole file first before creating the Docker container.
But that means I have to do that when I transfer the container to another machine.
Is there a way to append to the /etc/cron.d/pihole file in docker-compose so that it will persist when updating/transferring the container without creating external files?
I tried to mount the whole /etc/cron.d/ folder but when I do that and recreate the container, it doesn't create the pihole file inside it.
contents of /etc/cron.d/ when mounted in docker-compose:
gravity-on-boot
contents of /etc/cron.d/ when not mounted in docker-compose: