Hi guys! I have several docker containers running on my home server set up with separated compose files for each of them, including a Pihole one that serves as my home DNS. I created a network for it and a fixed IP but I couldn’t find a way to set fixed IPs to the other containers that use the Pihole network. Well everything works but every now and then I have problems because the Pihole cant start first and grab the fixed IP and some other container gets its IP so nothing works because everything depends on the Pihole to work. My Pihole compose is like this:
`networks: casa:
driver: bridge
ipam:
config:
- subnet: "172.10.0.0/20"
networks:
casa:
ipv4_address: 172.10.0.2`
My Jellyfin container as an example is like this:
`_networks: - pihole_casa dns: - 172.10.0.2
networks: pihole_casa: external: true__`
I read the documentation about setting fixed IP but all I got was using one single compose file and with 12 containers that seems like a messy solution… I couldn’t set fixed IPs with different compose files. Do you guys have any suggestion about it?
Thanks!
TLDR: I want to set fixed IPs to containers in different compose files so all of them use Pihole as DNS and don´t steal Pihole’s IP in the startup
Hello, I think you would prefer to connect via internal dns names rather than static IPs. I have a slightly similar setup with docker compose creating a network for my apps.
Docker compose that creates the network: https://github.com/HugoKlepsch/reverse-proxy-network/blob/master/docker-compose.yaml
Here I run my app and set the hostname. Note this app is on two docker networks, but for access from nginx it is on the “reverse_proxy” network: https://github.com/HugoKlepsch/buzz/blob/b160aab1649819acacb80964d7b19d7beb1712f6/docker-compose.yaml#L21
This compose is running nginx as a reverse proxy for my local apps. It uses the reverse proxy network: https://github.com/HugoKlepsch/reverse-proxy/blob/675e11d3d8a98e4692c6e6087de4428ac8d1ece8/docker-compose.yaml#L4
Here is a configuration file where I tell nginx where to find one of my apps on the reverse proxy docker network. Note the name references the name of the app and the docker network: https://github.com/HugoKlepsch/reverse-proxy/blob/675e11d3d8a98e4692c6e6087de4428ac8d1ece8/config/conf.d/sites-available/buzz.conf#L2
Wow what a reply! Thank you so much! I could set up all containers using the pihole as DNS using hostnames…your post helped me a lot!