top of page

How to deploy SpringBoot Application in AWS EC2 Instance using Docker

  • Writer: Subhasish Sahu
    Subhasish Sahu
  • Apr 21, 2020
  • 2 min read

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

ree

Create Repository


ree

ree

ree

Now install Docker on Windows



ree

Or

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




ree

Download and install



ree

ree

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:



ree

Once the Setup is completed, you will see below at


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



ree

Double Click on “DOCKER QUICKSTART TERMINAL”



ree

ree

ree

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:



ree

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.



ree

Lets Integrate Docker with IDE


Open IDE ( IntelliJ Idea) and GoTo


  1. File Setting

  2. Click on + sign

  3. Select “DOCKER MACHINE” option



ree

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



ree

CONFIGURE DOCKER REGISTRY



ree


Add Docker File



ree

From Terminal, run : mvn clean install



ree

ree

Then "Build Image on Docker"


ree

ree

If you get below error :


ree

Comment #( target folder)


ree

Once the build is successfully, push it to Docker Hub



ree

ree

ree

ree

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



ree

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



ree

ree

Start Docker Service


ree

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



ree

ree

ree

Add InBound Rules in AWS Security Group of your EC2 instance



ree

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>


ree




Comments


bottom of page