Problem: You cannot create a .jar after you change localhost to different value. Solution 2: You can activate Toggle 'Skip Tests' mode in Maven Tab before creating jar. (looks like circle, like this (/)) Solution 1: You should clean your maven project in common way, after that you should go to the terminal in intelliJ(i hope you use intelliJ, cause idk if it works in other IDE's). In terminal you should write next: mvn install -DskipTests=true and press CTRL+ENTER, if you press only enter it will not work. If this comment helped you just press the like button. P.S. IDK why the author avoid answer to this question, i read all his answers down below and that is just "ahh, yeah, you can't do this" without solution :/ P.P.S. If you try to use this command in terminal but it's not work and you just skipped the section above use ctrl+enter, it's might be a little bit confusing like it was for me)
I was not able to connect at first . Thanks for inspect command and IP fetch step. Now I'm able to connect. Thank you so much for keeping it simple and straight to the point. But now it throws error like "PSQLException: ERROR: relation "employees" does not exist" . Please suggest.
Is your @Entity & @Table("EMPLOYEES") correctly done? If you have installed pgadmin4 please check the schema got generated or not. Also you can set show-sql flag to true to see the executed self query by hibernate. Please do let me know sir. If you still need further assistance. Thank you
@@CodeVice111 Thanks for your reply. I was able to run the app from docker now. Database is empty on container. How generally developers test application if there is no data.. How can we get data on that DB.
@sreelathavk4450 Hibernate Jpa will take care of schema generation. All you need is just to add those annotations on top of your entiry class. There are many ways to do.. But I would request you to see a simple example on Hibernate Jpa + Spring boot CRUD example. Thank you Sir.
I am facing problem while making the jar file after change the host name with the container ip.I am not been able to create jar through maven clean and maven install or through the mvn package or through the build path and package .I have tried a lot.Please do help me.
At the beginning of your pom.xml where the groupId, artifact id, version etc.. are defined. Right below that you should have xml tag called jar. Secondly there should also be a pluging configured called maven-jar-plugin. But these things are by default configured when you freshly create a spring boot app. Anyways, give it a try.
Like my main comment please, if it helps Solution: You should clean your maven project in common way, after that you should go to the terminal in intelliJ(i hope you use intelliJ, cause idk if it works in other IDE's). In terminal you should write next: mvn install -DskipTests=true
the problem in this approch is tha the IP address of a container can change when the container is stopped and started again, or if the host machine is restarted. so you should change the properties file everytime the ip is changed. i think using docker compse is the better approch
You're right!, Easy approach would be ... 'docker create network my-custom-network' and then running both the containers under '--network=my-custom-network'. Then, container IP will no longer be needed.
If you are only running postgres on docker container, but not spring boot app. Then connecting to postgres db is quite simple. It should be through : localhost 5432 spring.datasource.url=jdbc:postgresql://localhost:5432/my-db spring.datasource.username=give_username spring.datasource.password=give-password Additionally u hv to specify spring.jpa.hibernate.ddl-auto=update spring.jpa.show-sql=true spring.jpa.properties.hibernate.format_sql=true spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQL81Dialect
@@CodeVice111 sorry, i mean 2 have two images: postgres and my-springapp, then i create a container of postgres image and it run ok, but when i create container of my-springapp it say refuse connect postgres. Why
Understood. When both apps hv their own container, then they hv be in the same network. Here is how: docker network create myNetwork Now u can include the netwoek using --net flag in the run cmd. Example: docker run -d -p 8000:8000 --net myNetwork --name springboot-container springboot-image docker run -d -p 5432:5432 --net myNetwork --name postgres-container postgres Try this out. Thanks for watching.
Hello , when i entered the details on pgAdmin and click save , Error occurs and error says "unable to connect to server : connection timeout expired".Can you help me with this , I am struggling with this error and can't seem to find the solution.
@@CodeVice111 After I had successfully dockerized my postgresql, it worked correctly, then I change the IP of application.properties file in my spring boot project, but when maven clean install, it encountered a problem with connecting attempt to DB
@@tranquythuong looks like, your application build process is modifying your db connection props. can you plz confirm by printing those values in your console to ensure all props are accurate!. And i also assume, your backend app is not containerized but postgres is.. and If so, then use localhost instead of container port.
@@CodeVice111 My postgres container work fine if I change the IP to localhost and run with intelliJ. I've solve my problem, when changed the IP I built the .jar file by using "mvn clean package -DskipTests" to skip testing step, and then I built the image, It was working correctly I'm still wondering why you just modify the application.properties file without cleaning and re-building .jar file with maven, and it still works :v
@@CodeVice111lets say i have postgres database alredy installed in my server. Now when dockerizIng my postgrres, how do i keep the extensions with it?
I think someone has already answered on this comcern in the comment section. Which is to use mvn clean install -DskipTests=true before building your .jar
After changing localhost to IpAddress in spring.datasource.url, I can't start the application directly from Intellij. Therefore, I can't run "mvn clean install" properly. Is that ok or am I doing something wrong? Is the whole point of Dockerfile not to run application from Intellij interface, rather running it everytime using the Dockerfile?
If you have already dockerized the postgres, but not yet dockerized the spring boot app... then you should use localhost instead of iPaddress in the db url. Ip address will only help you connecting to dockerized postgres when the spring boot app is also dockerized. 👌 thanks for watch.
Like my main comment please, if it helps Solution: You should clean your maven project in common way, after that you should go to the terminal in intelliJ(i hope you use intelliJ, cause idk if it works in other IDE's). In terminal you should write next: mvn install -DskipTests=true
@@PARTY6857 Good point. Better to use 'docker create network --network=custom-network' first, and then 'docker run' those two containers using --network flag. With this approach, it won't ask you to put IP in your config file. Leme know it helps... Thanks for watching.
Awesome, thanks! But I'm facing a problem after deploying the postgres database and creating its container. In the spring boot app, when I try to replace localhost by the IP of the container and run the the app, I see there's no connection happens to the db.
Please make sure you have configured the port correctly as well. And make sure before starting the spring boot container the postgres container should be up and running.
Like my main comment please, if it helps Solution: You should clean your maven project in common way, after that you should go to the terminal in intelliJ(i hope you use intelliJ, cause idk if it works in other IDE's). In terminal you should write next: mvn install -DskipTests=true
@@Kauaaa1010 I don't know to be honest, it might be a right solution, but for me it looks like a trick. And again: I don't know is there another ways to fix that :)
Thanks! Look forward to the docker compose tutorial!
sure!
The only video that helped me out :) Thank You very much! Good explanation
5 🌟 for this very well detailed explaination. I got the connection up and running thanks to your video. Much appreciated pal
Thanks for watching.
Problem: You cannot create a .jar after you change localhost to different value.
Solution 2: You can activate Toggle 'Skip Tests' mode in Maven Tab before creating jar. (looks like circle, like this (/))
Solution 1: You should clean your maven project in common way, after that you should go to the terminal in intelliJ(i hope you use intelliJ, cause idk if it works in other IDE's).
In terminal you should write next:
mvn install -DskipTests=true
and press CTRL+ENTER, if you press only enter it will not work.
If this comment helped you just press the like button.
P.S. IDK why the author avoid answer to this question, i read all his answers down below and that is just "ahh, yeah, you can't do this" without solution :/
P.P.S. If you try to use this command in terminal but it's not work and you just skipped the section above use ctrl+enter, it's might be a little bit confusing like it was for me)
BIG THANK YOU❤ I was spending hours with this problem for my bachelors project. Thanks 🙏🏽
Or you can activate Toggle 'Skip Tests' mode in Maven Tab before creating jar. (looks like circle, like this (/))
@@wtfWhoIsIt that's even better solution, than mine😀
@@wtfWhoIsIt Thank you, It helped alot.
Thank you so much!! Spent a lott of time on that & then found this comment.
Many thanks for this video.
I was not able to connect at first . Thanks for inspect command and IP fetch step. Now I'm able to connect. Thank you so much for keeping it simple and straight to the point. But now it throws error like "PSQLException: ERROR: relation "employees" does not exist" . Please suggest.
Is your @Entity & @Table("EMPLOYEES") correctly done?
If you have installed pgadmin4 please check the schema got generated or not.
Also you can set show-sql flag to true to see the executed self query by hibernate.
Please do let me know sir. If you still need further assistance. Thank you
@@CodeVice111 Thanks for your reply. I was able to run the app from docker now. Database is empty on container. How generally developers test application if there is no data.. How can we get data on that DB.
@sreelathavk4450 Hibernate Jpa will take care of schema generation. All you need is just to add those annotations on top of your entiry class. There are many ways to do.. But I would request you to see a simple example on Hibernate Jpa + Spring boot CRUD example.
Thank you Sir.
I am facing problem while making the jar file after change the host name with the container ip.I am not been able to create jar through maven clean and maven install or through the mvn package or through the build path and package .I have tried a lot.Please do help me.
At the beginning of your pom.xml where the groupId, artifact id, version etc.. are defined. Right below that you should have xml tag called jar. Secondly there should also be a pluging configured called maven-jar-plugin. But these things are by default configured when you freshly create a spring boot app. Anyways, give it a try.
Like my main comment please, if it helps
Solution: You should clean your maven project in common way, after that you should go to the terminal in intelliJ(i hope you use intelliJ, cause idk if it works in other IDE's).
In terminal you should write next:
mvn install -DskipTests=true
the problem in this approch is tha the IP address of a container can change when the container is stopped and started again, or if the host machine is restarted. so you should change the properties file everytime the ip is changed. i think using docker compse is the better approch
You're right!, Easy approach would be ... 'docker create network my-custom-network' and then running both the containers under '--network=my-custom-network'. Then, container IP will no longer be needed.
good explanation ,could you please share the repo link here
@@RamadeviMtech Pardon Sir. Didn't put those code into repo. And don't have the backup either.
Thanks for watching.
7:55 section eased me.... 😓
Thanks for episode. Very usefull!
I am having Spring-boot in my local machine and need to connect it to container which has database can i follow these steps for that ?
Then you can simply configure ur database through localhost..
i only ran Postgres container, in your video you only using dockerfile not docker-compose, but my spring boot application didn't connect to postgres
If you are only running postgres on docker container, but not spring boot app. Then connecting to postgres db is quite simple. It should be through : localhost 5432
spring.datasource.url=jdbc:postgresql://localhost:5432/my-db
spring.datasource.username=give_username
spring.datasource.password=give-password
Additionally u hv to specify
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQL81Dialect
@@CodeVice111 sorry, i mean 2 have two images: postgres and my-springapp, then i create a container of postgres image and it run ok, but when i create container of my-springapp it say refuse connect postgres. Why
Understood.
When both apps hv their own container, then they hv be in the same network. Here is how:
docker network create myNetwork
Now u can include the netwoek using --net flag in the run cmd. Example:
docker run -d -p 8000:8000 --net myNetwork --name springboot-container springboot-image
docker run -d -p 5432:5432 --net myNetwork --name postgres-container postgres
Try this out. Thanks for watching.
Hello , when i entered the details on pgAdmin and click save , Error occurs and error says "unable to connect to server : connection timeout expired".Can you help me with this , I am struggling with this error and can't seem to find the solution.
It happened with me once. And fixed it by reatarting the PGadmin. Thabks for warching
You didn't re-install maven for target folder, why does it still work?
What issue are you getting when you do that!
@@CodeVice111 After I had successfully dockerized my postgresql, it worked correctly, then I change the IP of application.properties file in my spring boot project, but when maven clean install, it encountered a problem with connecting attempt to DB
@@tranquythuong looks like, your application build process is modifying your db connection props. can you plz confirm by printing those values in your console to ensure all props are accurate!. And i also assume, your backend app is not containerized but postgres is.. and If so, then use localhost instead of container port.
@@CodeVice111 My postgres container work fine if I change the IP to localhost and run with intelliJ. I've solve my problem, when changed the IP I built the .jar file by using "mvn clean package -DskipTests" to skip testing step, and then I built the image, It was working correctly
I'm still wondering why you just modify the application.properties file without cleaning and re-building .jar file with maven, and it still works :v
Glad it works for you. Thanks for watching.
Nice content brother. What do you say about new UI in the IntelliJ idea?
Very compact, cleaner interface & yet little bit confusing for me when i switched to new one for the first time. 😄
Hi I have one question can't we pack postgres and my application in the same container and expose endpoints for both
Technically yes. But not recommended. Not even a best practice for prod env for obvious reasons.
@@CodeVice111lets say i have postgres database alredy installed in my server.
Now when dockerizIng my postgrres, how do i keep the extensions with it?
Please have a look: stackoverflow.com/questions/40040540/how-to-create-postgres-extension-inside-the-container
Do let me know if it doesn't work out
When i change localhost to ip adress, i cannot generate a jar file. how i can fix it please
I think someone has already answered on this comcern in the comment section.
Which is to use mvn clean install -DskipTests=true before building your .jar
Awesome job
Hi, don't we need to paste the PostgreSql dependencies in order to compile the project?
Yes you are right! you've to add the dependency in the pom.xml
How have you create jar file with container ip. It will generate errors
You're right. If you're creating a jar of your app without "externalizing env variables"! you'll end up getting errors.
After changing localhost to IpAddress in spring.datasource.url, I can't start the application directly from Intellij. Therefore, I can't run "mvn clean install" properly. Is that ok or am I doing something wrong? Is the whole point of Dockerfile not to run application from Intellij interface, rather running it everytime using the Dockerfile?
If you have already dockerized the postgres, but not yet dockerized the spring boot app... then you should use localhost instead of iPaddress in the db url. Ip address will only help you connecting to dockerized postgres when the spring boot app is also dockerized. 👌 thanks for watch.
Like my main comment please, if it helps
Solution: You should clean your maven project in common way, after that you should go to the terminal in intelliJ(i hope you use intelliJ, cause idk if it works in other IDE's).
In terminal you should write next:
mvn install -DskipTests=true
@@CodeVice111 you help me a lot with this comment, thanks a lot
@@CodeVice111 how did you generate Jar file after modifying the ip address?
@@PARTY6857 Good point. Better to use 'docker create network --network=custom-network' first, and then 'docker run' those two containers using --network flag. With this approach, it won't ask you to put IP in your config file. Leme know it helps... Thanks for watching.
Why don't you use docker compose file, i need it
@@hieutranhuu1048 please watch its second part. Find the link in the description. Thanks for watching
Awesome, thanks!
But I'm facing a problem after deploying the postgres database and creating its container.
In the spring boot app, when I try to replace localhost by the IP of the container and run the the app, I see there's no connection happens to the db.
Please make sure you have configured the port correctly as well. And make sure before starting the spring boot container the postgres container should be up and running.
Like my main comment please, if it helps
Solution: You should clean your maven project in common way, after that you should go to the terminal in intelliJ(i hope you use intelliJ, cause idk if it works in other IDE's).
In terminal you should write next:
mvn install -DskipTests=true
@@4wrk it works well on eclipse sts
@@4wrk It's happening with me and your tips work, but I'd like to know if it's a good way to avoid this error or just a trick.
@@Kauaaa1010 I don't know to be honest, it might be a right solution, but for me it looks like a trick. And again: I don't know is there another ways to fix that :)
Thank you, is the code available on github?
Apologies. I haven't not shared any snippets yet.
Thanks for watching.
Good jobs
why do you call it pUstgres? Its weird. Just say pOstgres.
@@mitakaka2 😊typo