Тёмный

How to dockerize your Spring Boot API | Docker Tutorial 

Random code
Подписаться 8 тыс.
Просмотров 85 тыс.
50% 1

A few weeks ago I created a video showcasing how we can set up a simple Spring Boot REST API, I now wanted to showcase how we can move this API into a Docker container and then run it.
IMPORTANT: OpenJDK is now deprecated and we should use "eclipse-temurin:17" instead. OpenJDK will still work but is not getting any new updates.
Note that the second line in the Dockerfile does not have any effect in this example; it merely searches for any JAR file, which can then be utilized, as the third line copies the JAR_FILE instead of directly placing the file.
Spring Boot API Tutorial: • How to create an REST ...
My channel publishes programming and software engineering videos, especially Java and Python. If that is what you want, do not hesitate to join me on this journey!
Subscribe to my RU-vid channel:
/ @randomcode_0

Наука

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

 

26 авг 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 76   
@kunalsingh-wb1ju
@kunalsingh-wb1ju 2 дня назад
I was stuck on the problem where I was not able to create the docker file for my project. Your video resolved my problem so easily. Thank you so much!
@cedescc7986
@cedescc7986 2 месяца назад
The video is nice but what impressed me even more is how you try to help almost everyone in the comments. You take time to answer everyone! Probs to you!
@Randomcode_0
@Randomcode_0 27 дней назад
Thank you, I have been a bit busy lately, but I am trying to once again get through most comments!
@2PacFearless
@2PacFearless 2 месяца назад
I have finally found the video how to make docker images with Java on RU-vid :). Thanks, for great work and clear explanation. !!!
@andilesimelane4771
@andilesimelane4771 11 месяцев назад
Short and clean, thanks you earned and subscriber... I hope I will learn a lot from this channel, I like we you explain even the -d that amazing thanks
@Randomcode_0
@Randomcode_0 11 месяцев назад
Awesome, thank you!
@ayushkumarsaksena7996
@ayushkumarsaksena7996 6 месяцев назад
Appreciate the simple explanation. Hope you make some more videos on Kafka end-to-end videos😅 Context: Struggling with edl kafka changes in docker file.
@theparten
@theparten Год назад
thanks hey i was able to spin up my small spring project to a docker image...be blessed❤...
@Randomcode_0
@Randomcode_0 Год назад
Glad it helped!
@Elysor832
@Elysor832 10 месяцев назад
Literally saved my life Thank you!
@Randomcode_0
@Randomcode_0 10 месяцев назад
Great to hear!
@olivierboisse1678
@olivierboisse1678 7 месяцев назад
What is the need for ARG JAR_FILE ?
@tank45b29
@tank45b29 16 дней назад
Goated tutorial
@Go_with-Christ
@Go_with-Christ Год назад
Good shit,why the 2nd line in dockerfile? You arent using it anywhere
@Randomcode_0
@Randomcode_0 Год назад
You are right, in this case, it does not do anything. Normally we would use: ARG JAR_FILE=target/*.jar COPY ${JAR_FILE} app.jar To copy any jar file, but in this video, I wanted to clearly showcase which file we were actually moving, so it stayed, and I can hear I am more or less explaining what it does but it is clearly not used in the video.
@user-oc6kb5kr6l
@user-oc6kb5kr6l 2 месяца назад
hi it didnt work for me for some reason cant connect them can you help me ?
@orph4nsx
@orph4nsx 3 месяца назад
is it running as production or dev? can i choose this option to make it running in production mode?
@theriddler2129
@theriddler2129 Месяц назад
Nice content!
@Randomcode_0
@Randomcode_0 27 дней назад
Glad you think so!
@szymaniuk1983
@szymaniuk1983 Год назад
maaaan this is a good guide. Nice work man
@Randomcode_0
@Randomcode_0 Год назад
Glad you think so!
@viktormykhasko9406
@viktormykhasko9406 11 месяцев назад
IMHO, the better idea is using JRE such as eclipse-temurin:17-jre-alpine instead of full JDK, the second line is useless or should be fixed and , maybe, from a security prospective - execute app in container as non root.
@samorita89
@samorita89 10 месяцев назад
Short and helpful, Thanks for the video!
@Randomcode_0
@Randomcode_0 10 месяцев назад
You're welcome! I'm glad you found the video helpful.
@abastecedorademateriales
@abastecedorademateriales 6 месяцев назад
awesome content !! thank you very much !!!
@NeoTechVision101
@NeoTechVision101 28 дней назад
Hi! hopefully someone will answer, what if I am in production and does a lot of changes every other time, is there a way to auto reload without needing to mvn clean package and rebuilding in the docker?
@Randomcode_0
@Randomcode_0 25 дней назад
At scale, a pipeline is used for updates. Keywords to investigate are CI/CD: CI (Continuous Integration) automatically tests the system, and CD (Continuous Delivery) automatically deploys changes. This is a huge field with many tools and customizable options. Hope this answers your question, otherwise, let me know.
@friedec3622
@friedec3622 10 месяцев назад
How to maven install using dockerfile?
@the_rocker7786
@the_rocker7786 Год назад
I think we can use either of ADD COPY
@Randomcode_0
@Randomcode_0 Год назад
In this case, ADD and COPY would do more or less the same. The main difference is that ADD can retrieve remote URLs and extract compressed files, while COPY only copies local files from the Docker host.
@ffffff3525
@ffffff3525 Год назад
брат, от души, ты спас мое положение у меня через неделю защита дипломки
@christianchapoco5472
@christianchapoco5472 Год назад
finally, thanks man
@Randomcode_0
@Randomcode_0 Год назад
Happy to help
@abraaorochapb6394
@abraaorochapb6394 5 месяцев назад
It works ! Ty
@mrowox
@mrowox Год назад
Best video. thumbs up
@Randomcode_0
@Randomcode_0 Год назад
Big thanks
@KlanBr1
@KlanBr1 Год назад
and if my app have a database connection? how i introduce my database inside the container, because i can´t stablish the conection because that.(sorry for my english)
@Randomcode_0
@Randomcode_0 Год назад
Your database should either have a public IP that you can connect to, or it needs to be accessible on the same network. In a more real world setup, your container would run on a cloud network where they could communicate, if a public endpoint is not desired.
@tolunaytoprakkaya2694
@tolunaytoprakkaya2694 7 месяцев назад
Thank you so much
@Randomcode_0
@Randomcode_0 6 месяцев назад
You're most welcome
@stoiandelev12345678
@stoiandelev12345678 Год назад
Hi, when i open localhost:8000, nothing to show. But when i start application with Spring everythik work normal.Can help?
@Randomcode_0
@Randomcode_0 Год назад
It is difficult to pinpoint the exact reason why it is not working, but my initial suggestions would be to check if the Docker container is connecting to the correct port that the Spring Boot application is exposing. If everything appears to be correct, you can consider accessing the container manually to investigate the issue further form inside the container.
@acethoughtless1596
@acethoughtless1596 9 месяцев назад
Hello! First of all Congratulation for your video!! Well i have a problem , when i docker running this , it gives me an error messages about communication problem between the application and the MySQL database server. Well the main error seems to be a "Communications link failure" with a "Connection refused" exception. I can understand that docker cant access my database server for some reason!. I checked my database and everything is alright. Can you understand ,why this is happening ?
@filipkajanovic1425
@filipkajanovic1425 7 месяцев назад
Hello there, did you manage to solve the issue ?
@mohammedislam733
@mohammedislam733 10 месяцев назад
But , when I have a hibernate crud app , it doesn't work , the error that the image can't connect to the jpa
@Randomcode_0
@Randomcode_0 10 месяцев назад
A jpa issue indicates your service cannot connect to your database. If your database is in another docker container they need to be on the same docker network, and the db needs an open port where the service can connect.
@mohammedislam733
@mohammedislam733 10 месяцев назад
@@Randomcode_0 can u please do a toturiel about it!
@Randomcode_0
@Randomcode_0 10 месяцев назад
I think that's a great idea! Which database are you using? Would you prefer a pure Docker setup or docker-compose?
@mohammedislam733
@mohammedislam733 10 месяцев назад
@@Randomcode_0 thanks bro for your response 🥰 , I'm new at both any toturiel will be good for me , I'm interested in your content, keep up the good work 😁
@codelib2337
@codelib2337 Год назад
Thanks a lot!
@Randomcode_0
@Randomcode_0 Год назад
No worries!
@skccharan
@skccharan Год назад
Thank you😊
@Randomcode_0
@Randomcode_0 Год назад
You're welcome 😊
@Hamdiyazarss
@Hamdiyazarss 6 месяцев назад
Thanks
@damonmorgan963
@damonmorgan963 11 месяцев назад
ERROR: failed to solve: dockerfile parse error on line 5: unknown instruction: ENTRYPOINT["java",
@damonmorgan963
@damonmorgan963 11 месяцев назад
used CMD, removed brackets and quotes. It worked
@Randomcode_0
@Randomcode_0 11 месяцев назад
Glad to hear you got it working.
@ismailforeveryone6889
@ismailforeveryone6889 Год назад
PLEASE i need a use case of spring boot 3 with zipkin running inside containers
@Randomcode_0
@Randomcode_0 Год назад
I have jsut been trying out zipkin, I now have a working system using docker-compose. Where I start a zipkin server in a contianer and a simple spring boot rest api in another container. Every call to the spring api is then called as a trace (but no saved in any database). I asssume this is more or less what you asked for? I will make vidoe showcaing and talking about this setup some time soon. Please let me know if this does not solve your use case.
@ismailforeveryone6889
@ismailforeveryone6889 Год назад
@@Randomcode_0 thank you so much for your answer , the prob was latest versions of openzipkin have changed it's default port so the new endpoint to post zipkin trace is zipkin: tracing: endpoint:zipkin-server:9411/api/v2/spans , not zipkin-server:9411/ (which used with the oldest versions (this update made with spring boot 3
@Randomcode_0
@Randomcode_0 Год назад
I am glad to hear you got it working!
@ismailforeveryone6889
@ismailforeveryone6889 Год назад
@@Randomcode_0 thank you so much dear coder , that's very kind of you
@ezraorina100
@ezraorina100 Год назад
Isn't openjdk deprecated?
@Randomcode_0
@Randomcode_0 Год назад
You seem to be right, I did not know that. It seems like we should use: "eclipse-temurin:17" instead. Thanks for letting me know
@anirudhhosur3827
@anirudhhosur3827 Год назад
It says [java, : notfound
@Randomcode_0
@Randomcode_0 Год назад
If you are running FROM a docker environment containing java it should no be a problem. When we use: ENTRYPOINT["java","-jar","/app.jar"] it is translated and run inside the docker container as: java -jar /app.jar Otherwise could you specify when you get this problem?
@stonedcodingtom9097
@stonedcodingtom9097 Год назад
Thx
@Hamdiyazarss
@Hamdiyazarss 6 месяцев назад
ADAMSIN
@CheeseStickzZ
@CheeseStickzZ 11 месяцев назад
Useless. Your example is so superficial there is nothing to learn from it. At least show how to do it with spring boot maven plugin and build packs, or how to reduce the image size by running lite versions of your jre.
@abulka
@abulka 10 месяцев назад
Dealing with dependencies would be useful info to cover too - my springboot app relies on some dependencies in my local .m2 maven repository, so crashes inside the container because the dependencies aren’t copied in. Trying to figure out the best way to do this.
@CheeseStickzZ
@CheeseStickzZ 10 месяцев назад
@@abulka it's not your fault it's because the tutorial is trash. You need to use spring boot maven plugin with build packs. The command is build image. Look it up on Google
@Randomcode_0
@Randomcode_0 10 месяцев назад
I recommend trying to build a fat JAR, which is a JAR file that includes dependencies bundled within it. While I can't guarantee it will solve your problem, it's a good starting point and the first thing I would test.
Далее
🎙А не СПЕТЬ ли мне ПЕСНЮ?
3:09:39
Просмотров 1,6 млн
Only I get to bully my sister 😤
00:27
Просмотров 17 млн
The intro to Docker I wish I had when I started
18:27
Docker Compose и Spring Boot 3.1
34:06
Просмотров 11 тыс.
How to create a great dev environment with Docker
29:55
Docker and Spring Boot
1:20:56
Просмотров 7 тыс.
Docker + Spring Boot - what you should know
21:59
Просмотров 15 тыс.
JAVA DTO Pattern Tutorial | Simplify Your Code
19:12
Просмотров 200 тыс.
MSI GAMING BLACK SCREEN / STUCK ON BOOT LED
1:00
Просмотров 5 млн
12 000 рублей за это? Xiaomi Fold 3
0:58
Просмотров 237 тыс.
Google Pixel 9/Pro Review: Gimmick or Good?
24:05
Просмотров 3,3 млн
ноутбуки от 7.900 в тг laptopshoptop
0:14