[Question] Best way to set up docker containers that depend on other container
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:
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
I think what you’re describing can be accomplished with docker-compose’s depends_on option. I’m not certain how it works across compose files, but that would be the first place I’d look.
You can split services into multiple YAML files (i.e. docker-compose.database.yml and docker-compose.backend.yml or whatever) and then use docker compose up -d docker-compose.database.yml docker-compose.backend.yml. Compose treats this like it would one file internally (i.e. the services are connected to each other via an internal network by default).
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.
Maybe not exactly what you are looking for but with Podman you can run any Docker container and control it via normal Systemd service files including all the fine grained control options that come with that.
Maybe I'm the one missing something. Are you saying I just have to use the LAN IP adress in the dns line in the compose file? I used the docker IP adress because I had some issues with containers not communicating with each other because every time I create a new container docker creates a new network for it. I'm gonna give it a try once I get home. Thanks!