3

so I'm really new to docker and I may be using it incorrectly here but it makes spinning up a mysql database REALLY easy so thats why I wanted to give it a shot rather than installing an instance on my remote (on LAN) machine.

So I want to access the MariaDB database from a different/remote machine however everywhere I look it seems to be providing outdated information, (even the official mariaDB documentation) doesnt provide the correct information, I tried what they say and I believe that is only for accessing the container from the same machine it's running on. Any article or *exchange answer I see tells you to go into the bash terminal of the container then change /etc/msql/my.cnf to have bind_address=0.0.0.0 and this is outdated as bind_address isnt even in my.cnf anymore it's located in /etc/mysql/mariadb.conf.d/50-server.cnf and in there there is a line that states

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.

I also couldnt find any refrence to an enviroment variable I could set in order to allow me to access it remotely so I really don't know where to look anymore about how to change the configuration in order to allow me to access the data base from my network.

And yes I have a user setup to allow remote connections. Any and all help is appreciated.

On a side note, it seems to be really hard to change this so it makes me believe this is bad practice or to be avoided and then that makes me believe I'm understanding docker wrong, I thought docker was supposed to allow you to run small instances of software that dont interact with each other so if one instance gets screwed up the rest dont but why are they so intent on not allowing a remote connection?

12
  • The bind-address defaults to all interfaces in the container. This is what is in the container. No config changes are needed.The official documents do list the mechanism, ` -p 3306:3306` when running the container. After that, configure your local networking to allow external access to port 3306 to remote hosts. Happy to clarify further. Sincerely, MariaDB Docker Library maintainer. Welcome to DBA Stack Exchange. Consider showing the execution of your container, and OS/container runtime environment information in your question.
    – danblack
    Commented Sep 10, 2021 at 5:14
  • Thank you for the response, it's a little late so I will get back to you ASAP in the morning but what your telling me is that I probably have some networking issue preventing me from accessing the port? I have it set to -p 3366:3306 in order to avoid that but I asume it's possible. I also posted in the mariaDB docker github, sorry about that should I delete that post? Commented Sep 10, 2021 at 5:28
  • The reason I didn't think it was a port issue was because docker just threw all my iptables rules out the window and rewrote them with it's own so I assumed it would handle opening/leaving that port open, do you think it has something to do with iptables rules? I don't want to start messing with dockers rules while I dont fully grasp docker networking and what rules could break it. Commented Sep 10, 2021 at 5:36
  • Sure. Show exact command line how you are starting the container. Try to connect locally on that machine to inside the container using the exposed port. Then try to connect remotely.
    – danblack
    Commented Sep 10, 2021 at 5:50
  • 1
    Right, so use an IP address (not 127.0.0.1) that corresponds to an IP address that is accessible from your remote side in the docker run -p {IP}:{exposed port}:3306 .....
    – danblack
    Commented Sep 10, 2021 at 8:27

2 Answers 2

0

The configuration of listening to remote connections is outside the container.

The container default configuration of mariadb listens on all interfaces within the container.

The docker/podman -p or -P is required to expose those interfaces to the host running the container.

If external connections are required listening to a non-local IP (part of -p, which by default will bind to all interfaces). Additionally firewall and routing configurations are required and may not be the default.

1

danblack already answered your question, but I'd like to point out that you probably shouldn't let your container communicate with the host system. Your doubt that this is a bad practice is correct, in my opinion.

What are you trying to do? Connecting your database manually? It's easy to do that. Run:

docker exec -ti <container_name> mariadb -u<user> -p<password>

Or do you want an application to use MariaDB? In that case, the application should run in a container. MariaDB container and the application container should access the same Docker network. This may be a bit tricky for a Docker beginner, but you can automate containers creation and maintenance with Docker Compose.

2
  • So like I said new to docker so maybe wrong, BUT I have a couple services running on raspberry pi and in the process of transferring them over to a different machine and I got the container bug so I'm containerizing all the things. Now a few of these services use mysql so I figured I'd just have all of their data on one instance, I know this doesn't require opening ports up but as I move services one by one I need to point a reverse proxy at mariaDB until theyre all transferred over then ill close off any open ports and allow only internal communication. Am i doing this right? Commented Sep 12, 2021 at 6:02
  • Sorry I can't answer this. It may be right or not. Commented Sep 12, 2021 at 12:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.