Deploy Spring Boot and MongoDB as Containers Using Docker Command & Docker-Compose | JavaTechie
ฝัง
- เผยแพร่เมื่อ 6 ก.ย. 2024
- In this tutorial I’m going to explain how to Deploy Spring Boot and MongoDB as Containers Using Docker Command & Docker-Compose
#javatechie #SpringBoot #Docker #MongoDB #Docker-Compose
GitHub:
github.com/Jav...
Blogs:
/ javatechie4u
Facebook:
/ 919464521471923
guys if you like this video please do subscribe now and press the bell icon to not miss any update from Java Techie
Disclaimer/Policy:
--------------------------------
Note : All uploaded content in this channel is mine and its not copied from any community , you are free to use source code from above mentioned GitHub account
Clearly explained , with hands on coding example . your tutorials are best .
Crisp and Clear explanation..Awesome content..Kudos..Way to go !!
you made life of a software developer so easy
Seedhi baat..no bakwas..keep it up
Why run MongoDb in docker container if we can connect the spring boot app with remote mongo cluster ?
Thank you. You've helped me so much!
Thank you very much that works. I spent an entire day trying to get it working on my mongodb client service that called the MongoDB
I was using
environment:
- MONGO_URL=mongodb://mongocontainer:27017/transactions
Kept failing
replace with
link
mongocontaine amend the appliction.yml to use data, and it works. Its just annoying that the docs did not list your way.
Thanks again.
Dear Basant, this entire Docker series is fantastic. You can simplify the topics in a such way that even kids can understand it easily. Just one question - if I have to execute it for Postgres or MySQL, will the process same or do I need to change anything?
No buddy you need to either use docker compose or kuhernetes deployment and service object for your database
@@Javatechie Thanks. I will start Kubernetes soon.
Very Helpful.. Great job you are doing. Thank you
It refreshed all my docker skills :D
Docker has many more concepts
Thank you Basant for the videos.
Thank you . it is very helpful...
How to use docker compose in production. It creates new container every time .
Yes it should
Thanks Techie
to create jar files why u r doing install u can use package and run it. Also 15:52 to dockerise we can use docker compose file
simply outstanding basant!!
Thank you so much, you helped me a lot 🙏
Thank You Very Much. Excellent content. Kudos , Keep it up.
Thanks buddy 😊
Where were u man ? Thank you so very much!
Thanks a lot! Very helpful...
very helpful. Thank you very much.
Awesome ❤️ ... Learning a lot from u sir . ☺️
rocking....as usual..bhai :)
It's just amazing !!
Thank you very much !!
The best
Nice....Thank You
How does your docker compos understand what spring-mongoDB image is? Do you need to create it before that? how can you do without an image with just docker-compose?
Maybe you dont know you should create controller and service folder and you can apply solid principle
great.really helpful
Thanks for the video bro
Awsome work bro, just has a question about how the spring boot application which is running locally is interacting with the MongoDB instance which is running into the container.
1) Like you have used the localHost URL and accessed the MongoDB containerized application how is it gets possible?
2) And also this tutorial is about two containerized applications linked and interacting with each other right.?
Will be very much thankful if you will address this with me.
If you observe I link my spring boot image with mongo db image .
@@Javatechie : Yes, then I am confused over there, as we are calling mongo DB image or container with local host application and not with spring boot image/container right.?
As you have linked --link two containers then how can localhost application interact with the containerized application.?
@@Javatechie is the link necessary? why not putting them in the same network?
Yes Linkin both images is mandatory
Great video tutorial! Have a question about connecting to an existing database e.g. MySQL or a NoSQL db like MongoDB through Docker. How can we get to do it? Thanks again for your very useful videos.
Thanks!
Helpful content...It would be great if you could create video on aws mock testing using local stack or how we can test Kubernetes as a Junit?
Thanks javatechie
Thanks
Book db is not getting created after Linking in mongodb, kindly help.
Is connection established successfully?
Actually I was not hitting the db using postman so it was not getting created there. Thanks for your quick response.
We have 3 microservices running if we have separate docker file ...then we have to use docker compose to link these 3 micro services ? To work as a single unit/ for communication ?
We can handle same with kuhernetes
Yes you can use docker compose if you don't have k8s.
🥰
After entering the in mongo using -it bash, Inside bash mongo command is not found
Excelente tutorial. The API works, but when I try to call the API from my front, I have CORS error. Could you please helme?
You need to enable cors from backend . Use below poc
@Bean public WebMvcConfigurer corsConfigurer() { return new WebMvcConfigurerAdapter() { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**").allowedMethods("GET", "POST", "PUT", "DELETE").allowedOrigins("*") .allowedHeaders("*"); } }; }
Just a small question if I run spring boot application locally without creating its container and try to connect application with mongo db container specifying localhost in connection url instead of mongo db container name will the connection be established?
No if you installed it in your local then you can make connections
@@Javatechie But why?.Its not like 2 different containers running with isolated networks and link is then established between them using --link command .I think when you were running the application on ide you were getting an error because container name was provided if instead you would have provided localhost there wouldn't have been any connection error
@@Javatechie could you please provide me an answer of the question I asked ?
Whenever we run the docker-compose we get this error any idea ? - > pull access denied for springboot-mongodb, repository does not exist or may require 'docker login': denied: requested access to the resource is denied, I ahve already logged in to my account.
Did you up your docker before you start compose ?
@@Javatechie it says this
Pulling springboot-mongodb (springboot-mongodb:1.0)...
ERROR: The image for the service you're trying to recreate has been removed. If you continue, volume data could be lost. Consider backing up your data before continuing.
need k8s tutorials for local development
Can u plz make a vedio on dockerizing angular+springboot+mongodb, I dockerized successfully springboot+mongodb with the help of this vedio, but I want dockerize angular as well
You can checkout my angular dockerize tutorial. already i uploaded it
@@Javatechie I have checked that also , but on how to combine all 3 containers in docker-compose file I have no idea,I have created docker image of angular, I m finding difficulty in combining that in docker compose file, if u can guide me on tat it will be great
Why are you using docker compose why not kuhernetes
@@Javatechie I tried to dockerize the full stack project using docker-compose it's working fine, your vedios helped lot thanks 👍, definitely I will kubrnetes also.
Edit: definitely I will use kubernetes also
Hi, Im getting 'com.mongodb.MongoSocketOpenException: Exception opening socket' when I try to run the docker container. When I run it in Intellij it works fine
what is the use of -d in docker run command?
In Docker, the `-d` flag is used to run a container in detached mode. When you run a container with this flag, it means the container will run in the background, and you'll get the command prompt back in your terminal immediately. This is useful when you don't want the terminal to be tied up by the running container, allowing you to continue using the terminal for other tasks.
Here's an example:
```bash
docker run -d my_image
```
Without `-d`, the container would run in the foreground, and you would see its output in your terminal.
👏🏻👏🏻👏🏻
Even after the docker login getting below error, is there anything missing ?
% docker-compose up
[+] Running 0/2
⠿ springboot-mongodb Error 6.7s
⠿ javatechiemongodb Error 6.7s
Error response from daemon: pull access denied for springboot-mongodb, repository does not exist or may require 'docker login': denied: requested access to the resource is denied
My boot is running on 8083 i used this - docker run -p 8083:9090 --name demoserver --link apmongodb:mono demoserver :1.0-new, stil not able to access the API - Any help ?
Why host name is not ip. How it works by using logical name. How link works. From openjdk 8, which jre it uses. I guess jre version might be different between local and container. If yes how the .class is not complaining about version error.
Container will setup the environment as information provided in docker file
@@Javatechie something on networking side we have to know.
Mvn install failed and jar not creating due to unknown mongo db host
Configure Mongo properties correctly
Please configure mongo properties correctly
@@Javatechie it's worked ,thanks bro
Thanks for this video
How do we connect to mongo db which is running without docker ?
Is your application running in container or outside container ?
@@Javatechie boot application on container and mongo db on windows local instance..i want to try this model...
No I don't think it's possible . Your DB instance must need to be run in container platform
can you make same for mysql
Hello - Thank you for this useful video.
When running the app container and linking it with mongodb container, I am getting this error:
com.mongodb.MongoSocketOpenException: Exception opening socket
Caused by: java.net.ConnectException: Connection refused (Connection refused)
Any idea what could this be caused by?
I think it is something to do with the yml file. Did you create the Book database in Mongodb container before you ran the application container or was it automatically created based on the configuration in yml file?
No database will auto create
@@Javatechie
Thank you. In the video you created the DB Docker image with a fresh instance of Mongodb. How was the Book DB created? Was that done outside the video?
@@MoeShammout let me save you some time ;) in application.properties name mongodb host same as your mongo container (in this video : javatechiemongodb) and not localhost because In a container localhost address itself but your mongodb is not in that container
@@hamzaelmhoujab2350 I've that issue event with the same name instead of localhost
Nice content but video quality is not good