top of page

How to deploy SpringBoot Application in AWS EC2 Instance using Docker

Writer's picture: Subhasish SahuSubhasish Sahu

Updated: May 25, 2020

Pre - Requisite :


  1. Java 1.8 ( or above)

  2. Intellij Idea IDE

  3. Docker

  4. Putty

  5. AWS Account

  6. Docker HUB Account


Please follow my previous blog on setting up of EC2 instance in AWS, creating a SpringBoot Application which will fetch the key/value pair from AWS Secret Manager and installing Putty.



After creation of the above, Lets install Docker locally on windows.


  1. Create Docker Account


Create Repository




Now install Docker on Windows



Or

If you are having Windows 10 (Home Edition), then you need to install an older version from ToolBox site.





Download and install




To run Dockers, your machine must have a 64-bit operating system running Windows 8 or higher. Additionally, you must make sure that virtualization is enabled on your machine.


Choose Start > Task Manager and navigate to the Performance tab. Under CPU you should see the following:



Once the Setup is completed, you will see below at


C:\Users\XYZ\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Docker



Double Click on “DOCKER QUICKSTART TERMINAL”






Type the docker run hello-world command and press RETURN. The command does some work for you, if everything runs well, the command’s output looks like this:



We need to note down the Docker IP assigned to this Container. We will access this IP to access the Applications installed inside Docker. To know the IP from the command prompt use command docker-machine ip.




Lets Integrate Docker with IDE


Open IDE ( IntelliJ Idea) and GoTo


  1. File Setting

  2. Click on + sign

  3. Select “DOCKER MACHINE” option




Once it is connected successfully, you will see container and images folder.




CONFIGURE DOCKER REGISTRY





Add Docker File




From Terminal, run : mvn clean install




Then "Build Image on Docker"




If you get below error :



Comment #( target folder)


Once the build is successfully, push it to Docker Hub







Go to docker Hub, you will be able to see the image being pushed.




Login to AWS EC2 instance using putty and install Docker( Refer previous blog for creating EC2 instance and connecting it with putty)





Start Docker Service



Run the image that was created and pushed to Docker Hub.It says that expose port 8080 for internal port 8090





Add InBound Rules in AWS Security Group of your EC2 instance




Open you browser and hit the url, you will be able to see the key/value retrieved from AWS Secret Manager


<EC2 instance IPv4 Public IP>: <8080>/<resource path>






 
 
 

Comments


bottom of page