After spending entire day debugging the communication failure issue between two containers, I learnt that I need to setup the network between the two containers and set the right port. Your video was spot on. A big thank you!
@@codingboot455 I was doing port forwarding to 3308 which is for public access and that port I am giving in applications.properties so I am able to connect from my local but when I was creating container of my application that time also I was giving port as 3308 which was wrong instead of that we have to give 3306
Thanks for this great tut man, I was stuck while trying to run the app but this video got me through. Hope you will make another docker tut with docker compose 🥺
Brother, this is the fantastic video. This is the only video that worked for me. It look a long but worked. Do you have any videos on Kubernetes as well?
Thanks, I spent alomost two days trying to find out how to connect MySQL to Spring Boot app inside Docker. I finally made it work because of your video. Could you please also provide Docker-compose file for this project if possible? Cheers.
I have a small question can the spring boot container establish the connection with MySQL container not by using container name and port 3306 (internal to MySQL container) but using localhost and 3307 port (the exposed one by MySQL) like we have established for dbeaver?
If you want to connect host machine MySQL from container for testing purpose then you can attach host network to spring boot app container as --network=host then localhost will point to host machine ( not recommended). Or you can use host machine IP address but make sure your host machine MySQL is configured to connect through IP address.
@@codingboot455 Actually I meant to say that when 2 containers want to interact with each other hosted on the same machine they cannot interact using localhost ,they can interact using internal ports and container names only ??
My God, you have no idea how hard I've struggled to get my spring project running in a vm. Seriously, thank you very much for such a great video. I would like to ask a couple of additional questions. I have downloaded a virtual machine to be able to do all this and only as a practice, but in reality what I need is to hire a VPS service from a company (like hostinger, for example), and I would perform all these steps again. But how could I associate the IP provided by the company? So it is the web open to any user. And my other question is, how could I do this to connect it with an Angular project?Because I have developed a website where the Front is made with Angular and the back with Spring. Again seriously thank you very much for this video. Greetings from Argentina!!!
I'm glad to help 🙂. After creating container you can map external port and ip address to your domain. Then access app from anywhere Ex: Using ip- YOUR-SERVER-IP:8080/springapp Using domain - your-domain/springapp Docker compose make more easy containerisation. Please follow this video : ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE--ekBqIvAGY4.html Thanks
@@codingboot455 thank you for your fast reply. Yeah, I created Env file which contains host, user , password and port. I run the Docker network command it's running fine in 9090. Which I same used as spring-net. When I am trying to do volume concept when I run docker run -d -p 3307:3306 --net spring-net -- name mysqldb - env-file myenv mysql. Showing error: Error response from deamon: pull access denied for myenv, repository doesn't exist or may require docker login
very nice job, brother. thanks a lot for the time and effort you have spent on this video to help me and others. deeply appreciate it. love to see more tutorial videos like this in the future.
Just a small question while running the spring boot application locally without creating the container, can I establish the connection directly with MySQL container with the exposed port 3307 in localhost. Basically can I by pass the sql connection created locally using Dbeaver community with container .I instead connect directly by passing localhost and port 3307 in yml file with MySQL container ?
If you want to connect MySQL Container from spring boot application running in eclipse(without container ) you can use localhost: as we are able to connect through Dbeaver . Just let me know if you have any other question or still have doubt .
@@codingboot455 mysql-docker-port means the port exposed by MySQL container on localhost ie 3307 instead of 3306 because 3306 is internal to container.I am saying 3307 specific to this video not in general
@@anubhavnigam7611 Very good question . Yes 3307(exposed port) not 3306. If you want to connect internal port then you need to attached HOST network to the container (which is not recommended ). docker run --net host jenkins/jenkins in the above example, you can access it from internal port 8080 because it is connected to the host machine network (but here Jenkins is able to access your host machine network which is not recommended)
Hi, at 13:00 can we change JDBC URL (replacing localhost with docker container name), username, password manually in the application.yml file as I am doing it in an ec2 machine. Please help I am unable to build a jar file after replacing localhost with container name.
@@codingboot455 Thanks for reply, my exact query is I cloned my spring boot project from my github & can able to build it while connecting it to mysql in my localhost. But when i started using mysql as container, i am unable to connect application to container (@ 13:00 You passed VM Arguments in an editor. Where exactly i should pass these arguments as i am not using any editor in ec2 machine). Thats my query
I am facing an issue. I have created one c# console application to fetch data from mysql database. I have created one container for my application and another container for mysql database. I have followed the same steps of yours. But getting an issue on last step, Unhandled exception. MySql.Data.MySqlClient.MySqlException : Unable to connect to any of the specified MySQL hosts.
@@codingboot455 It is connected. The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_212] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_212] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_212] at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_212] at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) ~[mysql-connector-java-8.0.28.jar!/:8.0.28] at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105) ~[mysql-connector-java-8.0.28.jar!/:8.0.28] at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151) ~[mysql-connector-java-8.0.28.jar!/:8.0.28] at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167) ~[mysql-connector-java-8.0.28.jar!/:8.0.28] at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:89) ~[mysql-connector-java-8.0.28.jar!/:8.0.28] at com.mysql.cj.NativeSession.connect(NativeSession.java:120) ~[mysql-connector-java-8.0.28.jar!/:8.0.28] at com.mysql.cj.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:843) ~[mysql-connector-java-8.0.28.jar!/:8.0.28] ... 58 common frames omitted Caused by: java.net.ConnectException: Connection refused (Connection refused) at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_212] at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_212] at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_212] at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_212] at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_212] at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_212] at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:156) ~[mysql-connector-java-8.0.28.jar!/:8.0.28] at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:63) ~[mysql-connector-java-8.0.28.jar!/:8.0.28]
@@codingboot455 where i can provide the path , is it like --env-file ../home/env for exemple 2 - how i can provide the path if the env file is in the spring project
@@meriemramli5058 Even its in spring boot app just provide complete path. actually env file should be outsiide of app folder. or you can keep env file in current directory where running docker command
Hi @Coding Boot. Thanks so much for the tutorial and I followed your tuorial but still getting "com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server" .. :(
@@codingboot455 Hi. I was using local host as datasource url in my properties file. Once I replaced that with docker host, this issue was solved. Thanks for your reply.