Skip to content

feat: add Dockerfile and .dockerignore for containerized builds#6

Merged
felipementel merged 3 commits into
mainfrom
add-dockerfile
May 16, 2026
Merged

feat: add Dockerfile and .dockerignore for containerized builds#6
felipementel merged 3 commits into
mainfrom
add-dockerfile

Conversation

@felipementel
Copy link
Copy Markdown
Owner

Why

This project had no container support, making it harder to run consistently across environments. Adding a Dockerfile and .dockerignore enables building and running the API as a Docker image with a reproducible, production-ready setup.

What changed

A multi-stage build approach is used to keep the final image lean:

  • Stage 1 (build)eclipse-temurin:21-jdk-alpine: copies the Maven wrapper and pom.xml first to leverage Docker layer caching for dependencies (dependency:go-offline), then copies src/ and produces the fat JAR via mvnw clean package -DskipTests.
  • Stage 2 (runtime)eclipse-temurin:21-jre-alpine: copies only the built JAR, runs it as a non-root user (appuser) for security, exposes port 8080, and includes a HEALTHCHECK against /actuator/health.

The .dockerignore excludes build artifacts (target/), IDE files, docs, and VCS metadata to keep the build context small and avoid accidentally invalidating cache layers.

Notes

  • The HEALTHCHECK probes /actuator/health — add spring-boot-starter-actuator to pom.xml if not already present, or update the endpoint accordingly.
  • No packages are installed in the runtime stage, so apk --no-cache is not needed there.

Multi-stage build with eclipse-temurin:21 (JDK for build, JRE for runtime).
Includes .dockerignore to optimize build context.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds initial containerization support for the Spring Boot API so it can be built and run reproducibly via Docker using a multi-stage build.

Changes:

  • Introduces a multi-stage Dockerfile (build with Maven wrapper; runtime with non-root user and healthcheck).
  • Adds a .dockerignore to reduce build context size and improve caching.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
Dockerfile Multi-stage build/runtime image definition for the API container.
.dockerignore Excludes common build artifacts/IDE/VCS files from Docker build context.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Dockerfile Outdated
Comment thread Dockerfile Outdated
Comment thread Dockerfile Outdated
felipementel and others added 2 commits May 16, 2026 16:55
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@felipementel felipementel merged commit d9d382a into main May 16, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants