How Can I Connect to MySQL in Docker Without Exposing Ports?

0
6
Asked By CuriousCoder42 On

I have a simple web app running in Docker on a cloud server, consisting of an Nginx container and a MySQL container, both on the same 'webapp' network. While Nginx has ports 80 and 443 exposed, MySQL does not have any ports exposed. I'm looking for a way to connect to the MySQL database from my local machine without opening up any ports. Is it possible to access the webapp network from the outside?

3 Answers

Answered By DevExpert91 On

If you have the option to SSH into your server, you can create a tunnel to access MySQL that way. Make sure you have SSH key authentication set up for security. Additionally, you might want to restrict the SSH access to your IP for added safety. Using a firewall to limit access to the MySQL port is also a good move.

Answered By TechSavvy23 On

One option is to set your Docker network to 'host'. This way, it can directly use the network of the host system, which simplifies access. Just check the Docker documentation for more details on the host network driver.

Answered By DockerNinja99 On

Since you want to keep MySQL off the public internet, it's smart that you've set it up on the internal Docker network. To connect from your local machine without opening the MySQL port to everyone, you can bind MySQL to localhost on the server and create an SSH tunnel. It's a safe way to access your database without exposing it.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.