Skip to content

Deploy Spring Boot with Docker on Elastic Beanstalk

This recipe shows how to package a Spring Boot application into a Docker image for Elastic Beanstalk deployments. Use this path when you need full control over the runtime image rather than the native Java platform.

Prerequisites

  • Spring Boot application prepared for container packaging.
  • Elastic Beanstalk Docker platform target environment.
  • Docker installed locally.
  • Understanding of Dockerfile and Elastic Beanstalk Docker deployment options.

What You'll Build

You will build a multi-stage Docker image for single-container Elastic Beanstalk deployments.

flowchart TD
    A[Spring Boot Source] --> B[Multi-stage Docker Build]
    B --> C[Container Image]
    C --> D[Elastic Beanstalk Docker Environment]
    D --> E[Application Endpoint]

Steps

  1. Create a multi-stage Dockerfile for the application.
FROM maven:3.9.9-eclipse-temurin-17 AS build
WORKDIR /src
COPY pom.xml .
COPY src src
RUN mvn --batch-mode clean package -DskipTests

FROM amazoncorretto:17-alpine3.20
WORKDIR /app
COPY --from=build /src/target/guide-0.0.1-SNAPSHOT.jar app.jar
ENV PORT=5000
EXPOSE 5000
ENTRYPOINT ["java", "-jar", "/app/app.jar"]
  1. Build and test the image locally.
docker build --tag eb-java:latest .
docker run --publish 5000:5000 eb-java:latest
  1. Initialize or update the Elastic Beanstalk environment on the Docker platform branch.
eb init
eb create "$ENV_NAME-docker"
  1. Deploy the containerized application version.
eb deploy "$ENV_NAME-docker"
  1. Validate endpoint behavior and logs.
eb status "$ENV_NAME-docker"
eb logs --all "$ENV_NAME-docker"

Verification

Use these checks after deployment:

docker build --tag eb-java:latest .
eb status "$ENV_NAME-docker"
curl --verbose "http://$CNAME/health"

Expected outcomes:

  • The container image builds successfully.
  • The app listens on the container port expected by Elastic Beanstalk.
  • Elastic Beanstalk deployment succeeds on the Docker platform.
  • /health returns the expected application response.

See Also

Sources