Docker Community Forums

Share and learn in the Docker community.

MariaDB/MySQL Refusing Connection to other containers

Hey, so a couple days ago I started moving all my services into containers. I have a MariaDB containers that holds multiple databases inside a single container for these services and I had it setup correctly and everything was working smoothly for a couple of days. Now I rebooted my machine and now these services can’t connect to any database and I’m not sure why or what’s going on.
I can access the container via docker exec -it mysql -uroot -ppassword and can also access it from another machine using mysql --host 192.168.1.162 --port 3306 -uroot -ppassword with no problems however these other containers are giving me errors that indicate they can’t connect to the database what so ever with error messages like:

[2021-09-13 05:48:24.530][service::util][WARN] Can't connect to database, retrying: DieselCon.
[CAUSE] BadConnection(
    "Can't connect to MySQL server on '192.168.1.162' (115)",
)

and

2021/09/13 05:49:49 [FATAL] [.../internal/route/install.go:75 GlobalInit()] Failed to initialize ORM engine: open database: dial tcp 192.168.1.162:3366: connect: connection refused

I would appreciate any and all help.

Hi

How did you start the mariadb container?
within docker network, they are all isolated within the docker network they’re allocated.

The way to do it, would be to split the mariadb up, 1 mariadb pr database scheme.
and then have the database container and the application container in the same docker network.

else you could consider running the mariadb in “host” mode, so it will look like the service is running on the host, and not in a container

It was an iptables issue, which is super weird. I thought I could remove the port rule as I have no issue’s accessing other containers admin pages via ports I dont have rules for and I figured because I could access the database/container/instance from another machine that it couldn’t be a firewall issue for obvious reasons. But it’s also really weird because even if i changed those services to use 127.0.0.1 rather than 192.168.1.162 (which is host’s IP) I figured it would just use loopback and not need an allow rule but it still didn’t work. Maybe I’m just understanding things incorrectly so definitely need to read up on (docker) networking, I see it inserts itself into iptables and I don’t want to be changing rules without understanding what docker is inserting and why.