How to run "pihole -g" when pihole is a container

I use Portainer to run pihole on my Raspberry Pi.

Under Group Management -> Adlists, the instructions note that the gravity database can be updated by typing "pihole -g"

I'd like to run this as a crontab but I'm not sure how. Since this is running as a container, that command is not recognized from the Raspberry Pi command line.

Any ideas on how to update pihole gravity on an automatic basis when it is running as a container?

There should be an existing cron set up by Pi-hole for a gravity update between 3 am and 5 am your local time every Sunday morning.

Thanks. Where would I find this entry to validate?

It's on this directory - a typical gravity cron will look like this:

-rw-r--r-- 1 root root 1754 Oct  2 08:11 /etc/cron.d/pihole
   5 3   * * 7   root    PATH="$PATH:/usr/sbin:/usr/local/bin/" pihole updateGravity >/var/log/pihole_updateGravity.log || cat /var/log/pihole_updateGravity.log

I have no pihole file within /etc/cron.d

I think this is because it's a container and is installed that way.

Please post the token generated by

pihole -d

or do it through the Web interface:

Tools > Generate Debug Log

The Docker host won't have that line, of course.
Did you check that file from inside of your container?

I found this after all here: Docker

Automatic Ad List Updates - since the 3.0+ release, cron is baked into the container and will grab the newest versions of your lists and flush your logs. Set your TZ environment variable to make sure the midnight log rotation syncs up with your timezone's midnight.

That doesn't supply an answer to your question: It just states that Pi-hole is handling periodic blocklist updates automatically.

No need to do this, there already is a preconfigured cron job updating once a week, as jfb has pointed out above.

If you'd insist on wanting to change that cron configuration, you could do so from inside the container. Refer to Docker's documentation on how to run a shell inside a container.

I would not recommend it, though: Any changes you apply to a Docker instance in that way will be lost on container restart.

Sorry if I'm being obtuse, but the documentation for the Docker Image states:

Automatic Ad List Updates - since the 3.0+ release, cron is baked into the container and will grab the newest versions of your lists and flush your logs. Set your TZ environment variable to make sure the midnight log rotation syncs up with your timezone's midnight.

Am I reading incorrectly that, at midnight, my container grabs the newest versions of my adlists?

This is what I was trying to solve for with respect to cron: a way to update the gravity database daily.

What am I missing here?

At midnight, the Pi-hole logs rotate. The cron for gravity update is on Sunday morning between 3 am and 5 am your local time. The Pi-hole cron scripts are here in a bare metal install (don't know if this is the same in docker).

-rw-r--r-- 1 root root 1754 Oct 14 13:36 /etc/cron.d/pihole
   17 4   * * 7   root    PATH="$PATH:/usr/sbin:/usr/local/bin/" pihole updateGravity >/var/log/pihole_updateGravity.log || cat /var/log/pihole_updateGravity.log
   00 00   * * *   root    PATH="$PATH:/usr/sbin:/usr/local/bin/" pihole flush once quiet
   @reboot root /usr/sbin/logrotate /etc/pihole/logrotate
   */10 *  * * *   root    PATH="$PATH:/usr/sbin:/usr/local/bin/" pihole updatechecker local
   1 15  * * *   root    PATH="$PATH:/usr/sbin:/usr/local/bin/" pihole updatechecker remote
   @reboot root    PATH="$PATH:/usr/sbin:/usr/local/bin/" pihole updatechecker remote reboot

Log rotation (happening daily) is different from a gravity list update (happening once a week).

By default, Pi-hole's normal blocklist update is once a week, which is sufficient, as blocklist updates don't occur on an hourly or even daily basis.

As said before, that update is controlled by cron which is incorporated into the container. In order to inspect that cron configuration, you'd have to access the respective files from within the container, also as mentioned before. You could also change the configuration files from within the container, but those changes wold be lost on container restart.

A Docker compatible way to define custom update frequencies would probably be to mount /etc/cron.d/ for your container from persistent storage, but you'd probably had to watch out getting file permissions right.

OK, I see where I misread it.

They say that CRON is baked in to update the adlist and do the log flush but then only talk about the logs being flushed at midnight (and don't mention grabbing the latest adlists).

That also explains why I wasn't seeing it updated.

That said, I was able to solve the problem by adding an entry at /etc/cron.daily that runs this:

docker exec pihole_container_name pihole updateGravity

I confirmed that works.

There is no problem with Pi-hole Docker.

Your initial request was:

No need to do that:
Pi-hole already comes with a preconfigured cron job that does automatically update blocklists, as pointed out by jfb in post#2.

Understood. You're correct. My initial post was how to update the gravity db automatically because it took me some time to realize it was automatic.

You are correct that there is no "problem" with the docker instance. The "problem" I was trying to solve was how to update the gravity db when I wanted it updated. I want to update the gravity db more than once a week and I don't want to have to use the web interface to do so manually so I was trying to figure out a way to do so via cron.

Consequently, I found out that adding a file to cron.daily as described did not work so I did an SSH into the device and added the following to the crontab:

0 6 * * * docker exec Pihole pihole updateGravity

Thanks for your help.