I have to Reset Pihole Password After Container Restart

Hello

I'm running pihole as docker container.

Recently pihole started not accepting my usual password and I have to ssh into the container to change it.

docker exec -it pihole /bin/bash
sudo pihole -a -p

The problem is that password change does not seem to persist and once I restart the container or stack, I have to reset the password again.

Below is my docker config.

pihole:
container_name: pihole
image: pihole/pihole:latest
ports:
- "8089:80/tcp"
- "53:53/tcp"
- "53:53/udp"
- "67:67/udp"
environment:
- TZ=Etc/UTC
- WEBPASSWORD=%randomAdminPassword%
- INTERFACE=eth0
volumes:
- ./volumes/pihole/etc-pihole:/etc/pihole
- ./volumes/pihole/etc-dnsmasq.d:/etc/dnsmasq.d
dns:
- 127.0.0.1
- 1.1.1.1
cap_add:
- NET_ADMIN
restart: unless-stopped

Is there a solution for this ?

Thanks

Is that literally your environment variable?

This is how it is set by IOTstack. I'm new this to docker, RPi and Pihole.

I have successfully set a new password as described above several times.

Wondering why the new password does not persist if I restart the container or stack. Shouldn't manually setting a password override whatever is set in docker-compose ?

That doesn't quite answer Dan's question:

This would be in addition to your manual password creation approach from within your container:

You shouldn't change the password from within the container.
Instead, use the WEBPASSWORD environment, as you already do, but exclusively.

You may have to readjust the way how you do that, though.

Is %randomAdminPassword% literally a part of your Pi-hole container configuration?

If so, replace that by some constant text.
Otherwise, your container would use whatever value is currently stored in %randomAdminPassword%, which -judging by its name containing random- may very likely change on every access or every restart, as probably configurable by your IOTstack.

Yes, %randomAdminPassword% is literally what my environment variable is. That is the default value that was included in my IOTstack installation.

This was the same config I used for few months and I did not have password issues until latest update.

I have changed it to a constant value and it works now so thanks for your help!

So when do you have to use sudo pihole -a -p ? Only in non docker installations ? i'm just wondering if including the password in the docker-compose file is the best practice.

That would be the expected behaviour if that container has been running without interruption during all that time. As an update requires a restart, that would be when a new random password from %randomAdminPassword% would have been set.

Yes.
As mentioned before, use the WEBPASSWORD environment variable for a dockered Pi-hole.

You have been very helpful. Thank you.

Just adding to this that %randomAdminPassword% is replaced at install time for IOTstack. %randomAdminPassword% is used in the template docker file, but the installation script searches for this string and updates it.

i have similar to your problem.
I'm running pi-hole as docker container too, i forgot my password and i reset it again, but every time i have to login i reset the password

and i found the solution to my problem,

logged in to portainer to check the container and i found that when i set the container the first time i typed the the admin password in the environment variable WEBPASSWORD= i.e-mypassword