proper usage of MySQL docker container while integrating with java application

Hi Community, Currently I am trying to implement some eCommerce functionality in java. And I would like to pull data from MySQL and utilize the same. So for this purpose I wanted to use MySQL docker container for the first time. And in my Linux server(host) I have installed docker and created a custom MySQL container with Image. so here the question is how to use this container in my local computer. And is this the way we suppose to access MySQL from local ?? or we create a different container for our local server by installing docker from the image? And how to access this container from host server (I mean the endpoint). Could someone please elaborate the clear use case of MySQL docker container. if you have any questions for my query please ask so that I will reply in comments.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there,

If you want to be able to access the MySQL container form the outside world, what you need to do is when starting the MySQL container is to bind the container to the host port with the -p flag. For example, for MySQL it would look like this -p 3306:3306.

However, what I’ve personally have been doing recently is avoiding running my SQL servers in containers. Instead, I use the Managed Database Clusters which come with high availability and disaster recovery. I still have my Java applications inside containers which then connect to the managed clusters.

That way I kind of get best of the both worlds. I can scale my application by adding more containers and I can scale my databases thanks to all of the features that come with the Managed Database Clusters.

Regards, Bobby