Ad Code

Ticker

6/recent/ticker-posts

AWS - Spring Boot - How to Deploy and Run Spring Boot Application as Docker Container inside AWS EC2 Instance

 In This post we are going to Deploy and Run Spring Boot Application as Docker Container within Amazon EC2 Instance. 

In my previous Post I have already shown how to create Docker Image and Publish to Docker hub registry using Jib Maven Plugin and using Jib Gradle Plugin for a Spring Boot Application.

So here we will follow the same Steps to create a Simple Spring Boot Application and Push as Docker Image using Gradle Jib Plugin. So our newly created image should be build and pushed to our Docker Hub repository


In one my Post we have seen how to create an Amazon EC2 instance in AWS Management Console and get connect to the EC2 instance using putty. So we will follow the same steps and create an  Amazon EC2 instance.

And here we will be able connect to our newly create Amazon EC2 instance through putty.

Next Update the packages on your EC2 instance using command
sudo yum update -y

Now to Run Spring Boot Application as Docker Container within Amazon EC2 Instance we need docker demon running in side our EC2 instance, So need to download and install docker inside our EC2 instance. Run the below command 

sudo yum install docker

Docker will install successfully inside our EC2 instance as show in the below snapshot:


Next we need to start docker as a Service within EC2 instance to run the Docker Containers
sudo service docker start

Next we need to pull the image of our Spring Boot Application from our docker hub repository and for this just go to Docker Hub Dashboard and copy the Docker Pull command 

docker pull rajivksingh13/my-gradle-teachlea:1.1.2

Now to got to EC2 Security Groups and Set the Inbound rules so that port 8080 should be accessible at http and https from our EC2 instance.

Once Security Group Settings Done we are ready to Run and Start our Spring Boot Application Container running inside EC2 instance.
Run the below command to run sand start the Spring Boot Application Container
docker run -i --rm -p 80:8080 rajivksingh13/my-gradle-teachlea:1.1.2
Now test the Spring Boot Application Running as Docker Container with Amazon EC2 Public IP DNS
http://ec2-43-204-107-144.ap-south-1.compute.amazonaws.com/helloAWS

Summary:

Congratulations! In this Demo We have successfully Deploy and Run Spring Boot Application is Docker Container within AWS EC2 Instance. We have used Putty to get connect to our EC2 instance from Windows System.

GitHub Link : rajivksingh13/teachlea
Please feel free to provide your valuable comments, Thanks.

Post a Comment

0 Comments

Ad Code