Nikhil Gupta
Nikhil Gupta

Reputation: 35

MySQL: How to access MySQL DB running inside a docker instance on a Ubuntu machine

I have a Ubuntu machine with IP = 172.16.12.134. On this Ubuntu machine, I have a docker instance of MySQL image running. The IP address of docker instance is like 172.18.0.8.

I am able to access db from ubuntu machine terminal with command like mysql -h 172.18.0.8 -P 3306 -u root -p.

Is there a way to access the db from outside(any other machine)the ubuntu machine?

like mysql -h 172.16.12.134 -P 3306 -u root -p.

I exported the port of docker in yml file as -port 3306:3306.

Upvotes: 0

Views: 39

Answers (1)

Arjan
Arjan

Reputation: 619

I don't see the problem here. Your first step would be to expose the MySQL service to your host machine, which you have done using -port 3306:3306.

You verified this to be working which means MySQL 'appears' to be running at 172.16.12.134:3306. Therefore the only thing left to do is allowing connections on port 3306 in your firewall. This way people can connect using your Ubuntu machine host IP and the respective port 3306.

Upvotes: 1

Related Questions