This article is a follow on from my previous one – “Example of a Spring Boot Microservice running on OSX/Docker Toolbox” which described how to create a Spring Boot application and deploy it to Docker Toolbox locally.

This article describes how to take that Docker image and deploy it onto Amazon Web Services Elastic Beanstalk.

Full source code is available on Github here: https://github.com/adrianmilne/spring-boot-docker-jaxrs-demo


Once you have a working Docker image of your application – there are 2 basic approaches to getting it up and running on Elastic Beanstalk. The first option is to create an archive and upload it directly, the second is to upload it to a docker repository (e.g. Docker Hub), and reference the image directly from there.

In this article – I’ll just run through the first option – creating an archive and uploading directly.

Step 1 – Create the Archive

As it’s a single file upload to Amazon – you will need to create a zip file containing the Spring Boot JAR and the associated Dockerfile. As I’m using Maven, I just added the Maven Assembly plugin to the pom.xml (and assembly.xml descriptor to the project) to handle this through the maven packaging process.

Example of assembly.xml – include our project JAR and dockerFile

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">

Example of Maven Assembly Plugin – create a ZIP file


With the assembly plugin set up – now when you run mvn package it will create a ZIP file in the target directory, which contains the Spring Boot application jar and the associated Dockerfile.

mvn clean package

Step 2 – Upload to Elastic Beanstalk

Once you have an Amazon AWS account setup – open the AWS console and got to the Elastic Beanstalk dashboard.

Screen Shot 2016-08-08 at 07.34.18

Create a new Application

Click on the ‘Create New Application’ link

Screen Shot 2016-08-08 at 07.34.02

Create a new environment

On the next page click on the ‘Create web server’ button option

Screen Shot 2016-08-08 at 07.34.31

Select a ‘Docker’ environment type

On the next page – select ‘Docker’ from the ‘Predefined configuration’ options:

Screen Shot 2016-08-08 at 07.34.43Upload your new ZIP file

Upload the zip file that was created from the Maven build

Screen Shot 2016-08-08 at 07.35.05Select a URL

You can accept the default one amazon provides – or overwrite it with your own. If you want to use your own domain name you can use Amazons Elastic IP to associate a static IP with the Elastic Beanstalk environment and point your domain at that IP.

Screen Shot 2016-08-08 at 07.36.49

No Additional Resources

No need to set up any additional resources for this demo

Screen Shot 2016-08-08 at 07.36.59

Accept Defaults

Just accept all the defaults on the next few screens. The final screen will display all the configuration you have specified and give you the option to ‘Launch’ the environment.

Screen Shot 2016-08-08 at 07.38.18

Launch complete

After clicking ‘Launch’ – it will take a little while, but eventually a green tick should appear indicating that everything is up and running

Screen Shot 2016-08-08 at 07.47.51

Open the site in a Browser

The root URL for your new Elastic Beanstalk environment is shown on your Dashboard – just copy and paste into your browser with your full path and you should see ‘Hello World’!



Screen Shot 2016-08-08 at 07.48.25Summary

This article runs though the basics of deploying a Spring Boot Docker image on Amazon Elastic Beanstalk. Full source code is available on Githib at https://github.com/corsoft/spring-boot-docker-jaxrs-demo.

(Visited 6,083 times, 1 visits today)
Deploying a Spring Boot Microservice To Docker / AWS Elastic Beanstalk
Tagged on:                     
InstagramPlease check your feed, the data was entered incorrectly.