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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

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
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

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Spring Boot With Kubernetes
  • Advanced Kubernetes Setup for Spring Boot App With PostgreSQL DB
  • Containerization and Helm Templatization Best Practices for Microservices in Kubernetes
  • [CSF] Using Metrics In Spring Boot Services With Prometheus, Graphana, Instana, and Google cAdvisor

Trending

  • Internal Developer Portals: Modern DevOps's Missing Piece
  • Beyond Linguistics: Real-Time Domain Event Mapping with WebSocket and Spring Boot
  • Streamlining Event Data in Event-Driven Ansible
  • Unlocking AI Coding Assistants Part 1: Real-World Use Cases
  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.

By 
Emmanouil Gkatziouras user avatar
Emmanouil Gkatziouras
DZone Core CORE ·
Feb. 07, 17 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
8.6K 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.

Related

  • Spring Boot With Kubernetes
  • Advanced Kubernetes Setup for Spring Boot App With PostgreSQL DB
  • Containerization and Helm Templatization Best Practices for Microservices in Kubernetes
  • [CSF] Using Metrics In Spring Boot Services With Prometheus, Graphana, Instana, and Google cAdvisor

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!