/etc/hosts file overwritten at container restart

Hi,

I've created an installer script for my pi-hole docker container, in this script I copy my blacklists, adlists, ... into the /etc/pihole folder, and a preconfigured list of local hostnames to the /etc/hosts file.

But apparently when the container is restarted the /etc/hosts file is overwritten. How can I prevent this? Or is there an other way to add my own hostnames to that file after a container restart?

Kind regards,
Frederic Depuydt

Shouldn't local hostnames go in /etc/pihole/local.list (at least in the non-Docker version)?

No. They should be either in /etc/hosts or in a configuration file in /etc/dnsmasq.d

I tried adding them by creating the /etc/dnsmasq_static_hosts.conf file, but that didn't work for the web interface, not sure if the file is even used.

When adding the hosts file content to a file inside /etc/dnsmasq.d it returns a syntax error for that file.

Note: I'm not using the Pi-Hole as DHCP.

I've found a solution in this thread: HOWTO: Using pi-hole as LAN DNS server

Added a 02-lan.conf file in /etc/dnsmasq.d with content:

addn-hosts=/etc/pihole/lan.list

And added my local hostnames to the lan.list file in /etc/pihole

Thanks @jfb for pointing me towards dnsmasq as a possible solution.