Тёмный

How To Dockerize Spring Boot Application & PostgreSQL Database 

CodeVice
Подписаться 477
Просмотров 29 тыс.
50% 1

Click here to stay tuned with all the upcoming videos:
/ @codevice111
- - -
Learn how to run spring boot application and PostgreSQL database in two different docker containers and perform CRUD operation through Swagger3.
NOTE: We're not using docker-compose to create separate containers for running Spring Boot and PostgreSQL locally.
- - -
Previous Videos:
- - - - - - - - - - - - - -
[Masking Sensitive details from console and Rolling-File appender]: • Mask, Hide & Replace S...
- - -
Development Frameworks & Tools:
#docker
#spring
#springboot
#swagger
Thank you so much for going through the detailed description. Feel free to add comments with your suggestions.
Don't forget to subscribe
/ @codevice111

Опубликовано:

 

11 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 67   
@4wrk
@4wrk 10 месяцев назад
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)
@posichief365
@posichief365 8 месяцев назад
BIG THANK YOU❤ I was spending hours with this problem for my bachelors project. Thanks 🙏🏽
@wtfWhoIsIt
@wtfWhoIsIt 5 месяцев назад
Or you can activate Toggle 'Skip Tests' mode in Maven Tab before creating jar. (looks like circle, like this (/))
@4wrk
@4wrk 5 месяцев назад
@@wtfWhoIsIt that's even better solution, than mine😀
@shashankrana03
@shashankrana03 Год назад
Thanks! Look forward to the docker compose tutorial!
@CodeVice111
@CodeVice111 Год назад
sure!
@TheGruwy10
@TheGruwy10 4 месяца назад
The only video that helped me out :) Thank You very much! Good explanation
@hamdiaminehkh
@hamdiaminehkh 4 месяца назад
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
@CodeVice111
@CodeVice111 4 месяца назад
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.
@AnkushMohanty-z1r
@AnkushMohanty-z1r Год назад
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.
@CodeVice111
@CodeVice111 Год назад
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.
@4wrk
@4wrk 10 месяцев назад
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
@Louyark
@Louyark 2 месяца назад
5 🌟 for this very well detailed explaination. I got the connection up and running thanks to your video. Much appreciated pal
@CodeVice111
@CodeVice111 2 месяца назад
Thanks for watching.
@voluantran5090
@voluantran5090 Год назад
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
@CodeVice111
@CodeVice111 Год назад
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
@voluantran5090
@voluantran5090 Год назад
@@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
@CodeVice111
@CodeVice111 Год назад
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.
@SAGARMN-ho9md
@SAGARMN-ho9md 4 месяца назад
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 ?
@CodeVice111
@CodeVice111 4 месяца назад
Then you can simply configure ur database through localhost..
@Doisgiga
@Doisgiga Год назад
Nice content brother. What do you say about new UI in the IntelliJ idea?
@CodeVice111
@CodeVice111 Год назад
Very compact, cleaner interface & yet little bit confusing for me when i switched to new one for the first time. 😄
@vishalch9127
@vishalch9127 Год назад
I am facing error while running the docker container, i found that in logs. The error is I am unable to connect to postgres. " Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connection"
@CodeVice111
@CodeVice111 Год назад
Suspecting:: Hope your are giving ipv4(you can get it by runnung 'docker inspect containerId' as shown in the video) instead of localhost. If you've changed the port of postgres then obviously you have to give the correct one. Also suspecting:: Make sure all the connection properties are correct incase if you're getting it from env variable.
@gvsphaniteja
@gvsphaniteja 11 месяцев назад
Did it get resolve?
@tranquythuong
@tranquythuong 4 месяца назад
You didn't re-install maven for target folder, why does it still work?
@CodeVice111
@CodeVice111 4 месяца назад
What issue are you getting when you do that!
@tranquythuong
@tranquythuong 4 месяца назад
@@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
@CodeVice111
@CodeVice111 4 месяца назад
@@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.
@tranquythuong
@tranquythuong 4 месяца назад
@@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
@CodeVice111
@CodeVice111 4 месяца назад
Glad it works for you. Thanks for watching.
@bsal5347
@bsal5347 9 месяцев назад
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
@CodeVice111 9 месяцев назад
It happened with me once. And fixed it by reatarting the PGadmin. Thabks for warching
@TheRagreis
@TheRagreis Год назад
Hi, don't we need to paste the PostgreSql dependencies in order to compile the project?
@CodeVice111
@CodeVice111 Год назад
Yes you are right! you've to add the dependency in the pom.xml
@hieutranhuu1048
@hieutranhuu1048 3 месяца назад
Why don't you use docker compose file, i need it
@CodeVice111
@CodeVice111 3 месяца назад
@@hieutranhuu1048 please watch its second part. Find the link in the description. Thanks for watching
@diraneserges6076
@diraneserges6076 Месяц назад
When i change localhost to ip adress, i cannot generate a jar file. how i can fix it please
@CodeVice111
@CodeVice111 Месяц назад
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
@ayushjaiswal4449
@ayushjaiswal4449 10 месяцев назад
Hi I have one question can't we pack postgres and my application in the same container and expose endpoints for both
@CodeVice111
@CodeVice111 10 месяцев назад
Technically yes. But not recommended. Not even a best practice for prod env for obvious reasons.
@jirehla-ab1671
@jirehla-ab1671 6 месяцев назад
​@@CodeVice111lets say i have postgres database alredy installed in my server. Now when dockerizIng my postgrres, how do i keep the extensions with it?
@CodeVice111
@CodeVice111 6 месяцев назад
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
@kyeiiih4422
@kyeiiih4422 Год назад
Awesome job
@AbanoubAsaad-YT
@AbanoubAsaad-YT Год назад
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.
@CodeVice111
@CodeVice111 Год назад
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.
@4wrk
@4wrk 10 месяцев назад
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
@OnWeek
@OnWeek 8 месяцев назад
@@4wrk it works well on eclipse sts
@Kaua3414.
@Kaua3414. 17 дней назад
​@@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.
@4wrk
@4wrk 16 дней назад
@@Kaua3414. 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 :)
@tomsowyer4956
@tomsowyer4956 Год назад
Thanks for episode. Very usefull!
@josequintin2467
@josequintin2467 Год назад
Good jobs
@basheeral-momani2032
@basheeral-momani2032 Год назад
Thank you, is the code available on github?
@CodeVice111
@CodeVice111 Год назад
Apologies. I haven't not shared any snippets yet. Thanks for watching.
@luckytheracer4557
@luckytheracer4557 11 месяцев назад
How have you create jar file with container ip. It will generate errors
@CodeVice111
@CodeVice111 11 месяцев назад
You're right. If you're creating a jar of your app without "externalizing env variables"! you'll end up getting errors.
@checkmate6988
@checkmate6988 Год назад
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?
@CodeVice111
@CodeVice111 Год назад
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.
@4wrk
@4wrk 10 месяцев назад
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
@OnWeek
@OnWeek 8 месяцев назад
@@CodeVice111 you help me a lot with this comment, thanks a lot
@PARTY6857
@PARTY6857 4 месяца назад
@@CodeVice111 how did you generate Jar file after modifying the ip address?
@CodeVice111
@CodeVice111 4 месяца назад
@@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.
@mitakaka2
@mitakaka2 2 месяца назад
why do you call it pUstgres? Its weird. Just say pOstgres.
@CodeVice111
@CodeVice111 2 месяца назад
@@mitakaka2 😊typo
Далее
Dragon Blood Whitening Cream
00:35
Просмотров 4,3 млн
Katta janjal
00:29
Просмотров 315 тыс.
Docker Compose и Spring Boot 3.1
34:06
Просмотров 12 тыс.
Redis за 20 минут
23:22
Просмотров 145 тыс.
Docker and PostgreSQL in [10 Minutes]
21:06
Просмотров 270 тыс.
Dragon Blood Whitening Cream
00:35
Просмотров 4,3 млн