'Docker Container cant connect to MySQL database

I have a MySQL instance running in a docker container, available on my host system at port 3333. I already tested the connection via the MySQL workbench to verify, that the user I created is able to login to the SQL server.

I also have a wikijs (installation guide found here) instance running in a container. I have provided all the required environment variables, including the information of the user I already tested, but the container always says that the connection was refused.

Does anybody have an idea on what the problem is?



Solution 1:[1]

No information does not help solving your problem but a wild guess:

By default docker containers are joining a virtual network separate from host named bridge.

You can't reach host by localhost or 127.0.0.1, because this is pointing to your docker container itself. To reach host directly either let container use hosts IP by --network=host (with some disadvantages) or use host.docker.internal as DNS-Name instead of an IP.

BUT you should not take the way over host, connect directly to the mySQL-container by using the alias or IP or the container. You'll get that by docker inspect <containername>. No need to map ports then..

Solution 2:[2]

Kindly try adjusting the port to 3306 and see if it works

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 araisch
Solution 2 Oumar Marshud