DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Trending

  • Design Patterns for Microservices: Ambassador, Anti-Corruption Layer, and Backends for Frontends
  • Mastering Time Series Analysis: Techniques, Models, and Strategies
  • How To Check IP Addresses for Known Threats and Tor Exit Node Servers in Java
  • The SPACE Framework for Developer Productivity
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Push Spring Boot Docker Images on ECR

Push Spring Boot Docker Images on ECR

This in-depth look at how to Spring Boot Docker images to the Amazon EC2 Container Registry provides a good example of Spring, Java, the cloud, and container usage.

Emmanouil Gkatziouras user avatar by
Emmanouil Gkatziouras
CORE ·
Feb. 07, 17 · Tutorial
Like (4)
Save
Tweet
Share
7.91K Views

Join the DZone community and get the full member experience.

Join For Free

On a previous blog, we integrated a Spring Boot application with EC2. It is one of the rawest forms of deployment that you can have on Amazon Web Services.

On this tutorial, we will create a docker image with our application which will be stored to the Amazon EC2 container registry.

You need to have the AWS CLI tool installed.

We will get as simple as we can with our Spring application, therefore we will use an example from the official Spring source page. The only changes applied will be on the packaging and the application name.

Our application shall be named ecs-deployment

 rootProject.name = 'ecs-deployment' 

Then we build and run our application

 gradle build gradle bootRun 

Now let’s Dockerize our application.
First, we shall create a Dockerfile that will reside on src/main/docker.

 FROM frolvlad/alpine-oraclejdk8 VOLUME /tmp ADD ecs-deployment-1.0-SNAPSHOT.jar 
 app.jar 
 RUN sh -c 'touch /app.jar' 
 ENV JAVA_OPTS="" ENTRYPOINT 
 [ "sh", "-c", 
 "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ] 

Then we should edit our Gradle file in order to add the Docker dependency, the Docker plugin, and an extra Gradle task in order to create our Docker image.

buildscript {
    ...
    dependencies {
        ...
        classpath('se.transmode.gradle:gradle-docker:1.2')
    }
}

...
apply plugin: 'docker'


task buildDocker(type: Docker, dependsOn: build) {
    push = false
    applicationName = jar.baseName
    dockerfile = file('src/main/docker/Dockerfile')
}

And we are ready to build our Docker image.

 ./gradlew build buildDocker 

You can also run your Docker application from the newly created image.

 docker run -p 8080:8080 -t com.gkatzioura.deployment/ecs-deployment:1.0-SNAPSHOT 

The first step is to create our ECR repository

 aws ecr create-repository --repository-name ecs-deployment 

Then let us proceed with our Docker registry authentication.


 aws ecr get-login 


Then run the command given in the output. The login attempt will succeed, and you're ready to proceed to push your image.

First, tag the image in order to specify the repository that we previously created, and then do a Docker push.


 docker tag {imageid} 
 {aws account id}.dkr.ecr.{aws region}.amazonaws.com/ecs-deployment:1.0-SNAPSHOT 
 docker push {aws account id}.dkr.ecr.{aws region}.amazonaws.com/ecs-deployment:1.0-SNAPSHOT 

And we are done! Our Spring Boot Docker image is deployed on the Amazon EC2 container registry.

You can find the source code on GitHub.

Docker (software) Spring Framework Spring Boot push

Published at DZone with permission of Emmanouil Gkatziouras, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • Design Patterns for Microservices: Ambassador, Anti-Corruption Layer, and Backends for Frontends
  • Mastering Time Series Analysis: Techniques, Models, and Strategies
  • How To Check IP Addresses for Known Threats and Tor Exit Node Servers in Java
  • The SPACE Framework for Developer Productivity

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: