Change cron schedule in Docker

My pihole docker is shut down automatically at 12am and starts again at 7am.

I noticed that the cron job schedule for updating the gravity falls in that range.

In non-docker deployment, I would just edit the /etc/cron.d/pihole manually, but that's not possible in docker since it's not permanent.

Can I just edit the /etc/cron.d/pihole through COMMAND in docker-compose?

Why are you shutting down your network DNS server for 7 hours a day?

Because there are no employees at night

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

Thank you!

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 can also change the cron schedule of log rotation in cron.d/pihole right?

Sure.

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

What are you typing exactly for the mount in your compose? Can you post the full yaml file here?

It looks like you are trying to mount ..../etc-cron.d which is a directory on to /etc/cron.d/pihole which is a file.

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

What does ls -lah /run/desktop/mnt/host/e/Docker_pihole/etc-cron.d/ show?

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?

Dan has pinpointed it, I think:
You are trying to mount a file within your container, but Docker may create a given volume as a directory if that file doesn't already exist at the given location, see Docker compose Are you trying to mount a directory onto a file (or vice-versa)? - Stack Overflow and "not a directory: unknown: Are you trying to mount a directory onto a file" error produced when mounting a single file on a container · Issue #1795 · docker/compose-cli · GitHub

Try to shut down your container and maybe Docker as well, manually create a file pihole at the required location, and restart your Pi-hole container.

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.
  1. contents of /etc/cron.d/ when mounted in docker-compose:
gravity-on-boot
  1. contents of /etc/cron.d/ when not mounted in docker-compose:
e2scrub_all  
gravity-on-boot  
php  
pihole

Are you using the Windows filesystem for your mount points?

Yes I am using Docket Desktop for Windows

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