I’m trying to connect my Nextcloud container to an external MySQL Database.
I can create the container with docker-compose and also access the setup page from Nextcloud, but I’m not able to connect to my existing database which I created with VESTAcp.
I guess MySQL and Docker cannot communicate together, but I have no idea why. I (hopefully) changed the MySQL bind address to the IP Range 184.108.40.206\16 to connect them together, but I have no idea if this is the right way.
I don’t get it. You have an external database, but you do start a MariaDB instance, that your nextcloud-app depends on, but you don’t want to access it??
If you want to access the MariaDB-container instance, the MYSQL_HOST is database or mariadb_container. If you have a database running on your host-machine, it is (as already mentioned), that machine ip.
From a container perspective, localhost or 127.0.0.1 always belong to the containers virtual network interface, just as it would be use on any physical host. All containers get its own local ip and a host name that can be used to resolve the route to the container. If you expose a port, like you do with the web service, you bind the internal port (80 in your case) with the host machine port (8080). If you don’t expose it to the host machine, it will still be reachable from other services in the same stack of network using the service name or host name.
So please try to use database or mariadb_container as the MYSQL_HOST.
If you look at Docker Hub, they connect adminer to a mariadb without any other configuration, since adminer is looking for the exposed db-port on all found containers in the stack.
I was able to solve this same issue simply by adding docker backend exe to windows firewall (Linux would be similar). https://arnav.jain.se/2019/allow-docker-through-windows-firewall/
You probably need to add port to your DB service as well. I use python and Jupyter notebook to connect to MariaDB, but any compatible tool should work. Hope that helps. I hope to post a note book on the subject soon.