My MariaDB Docker container changes networks anytime my server resets reddit / selfhosted ---------------------------------------------------------------------- notdoreen · 2023-11-14 16:30 I've had to reset my Ubuntu server a couple of times in the last year and there's one thing I noticed that happens to my MariaDB container: The IP address goes up by one each time. For example, it was [172.17.0.10](https://172.17.0.10) and now its [172.17.0.11](https://172.17.0.11). The ports remain the same but this breaks any app that's using the DB since the app is still looking to connect to .10 and not .11. I'm not quite sure if this happens to other containers (I think it might) but other containers connect using the host + port. MariaDB connects using the IP address shown in portainer. The one that matches the network bridge. I'm not well-versed in networking and I've been asking about recommendations for Udemy/Coursera courses on the topic (Feel free to suggest one). If possible, I'd like to revert the container's Ip address back to [172.17.0.10](https://172.17.0.10) and prevent it from changing again, OR find a way to connect apps to the container using the localhost instead of the container IP address. ​ My workaround has been to go to the affected apps and point them to the new IP address when it changes but I'm hoping to find a way to eliminate the need for this. Thoughts? ---------------------------------------------------------------------- keananmeier · 2023-11-14 16:45 Assuming the other apps are all on the same host Easiest way is to just use the name of the docker container and port to connect instead of an IP address. Ex:// container_name:1234 Another option is have all the containers be a part of the same docker network and then you can use localhost plus port. ---------------------------------------------------------------------- thekrautboy · 2023-11-14 16:46 Dont use IPs for Docker networking. Use container names as hostnames, very simple. So set your web app (or whatever) to connec to `mariadb:3306` or whatever container name and port you have set. /r/Docker ---------------------------------------------------------------------- thekrautboy · 2023-11-14 16:50 > Another option is have all the containers be a part of the same docker network and then you can use localhost plus port. That wont work, localhost would connect to the source container itself, not the Docker host and not the other container. You could "piggy-back" a service onto the networking of another, then localhost would become that second container. Or use the special host.docker.internal hostname to refer to the Docker host from inside the Docker network, for special cases. ---------------------------------------------------------------------- notdoreen · 2023-11-14 16:54 Thank you. I had no idea I could do this! ---------------------------------------------------------------------- thekrautboy · 2023-11-14 17:03 > EDIT: BTW I didn't use Dicker-compose for this container. It's one of my older ones before I even knew what compose was. Simple enoiugh to just "switch that container" to use compose. If you dont remember the entire `docker run` command you used to deploy it, and you dont want to manually look up the entire container config, you can try a tool like [autocompose](https://github.com/Red5d/docker- autocompose) to try to "export" the config as a compose file. Then simply stop and remove the container and deploy it fresh with compose. Just make sure you have the same volumes mounted for persistent data (if that container wants any). ---------------------------------------------------------------------- notdoreen · 2023-11-14 17:34 Thank you! ---------------------------------------------------------------------- thekrautboy · 2023-11-14 17:48 No problem :) ---------------------------------------------------------------------- thekrautboy · 2023-11-14 17:54 Also note the edit to my original comment above.