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
Dockerfileand 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¶
- Create a multi-stage
Dockerfilefor 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"]
- Build and test the image locally.
- Initialize or update the Elastic Beanstalk environment on the Docker platform branch.
- Deploy the containerized application version.
- Validate endpoint behavior and logs.
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.
/healthreturns the expected application response.