0

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.

2
  • is there a way to access db with command like "mysql -h 172.16.12.134 -P 3306 -u root -p" ? Commented Dec 17, 2018 at 14:50
  • or is there a server available (like workbench) which I can install on that ubuntu machine and that server can be connected to usual workbench ? Commented Dec 17, 2018 at 14:53

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

The only thing I'd add to this answer is to forget the Docker-internal IP address (172.18.0.8 in the question) exists at all; this is one of the contexts where it's not useful, and you don't ever need it directly.
I am not able to connect from host using "mysql -h 172.16.12.134 -P 3306 .. " but " mysql -h 172.18.0.8 -P 3306..."

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.