Files
apirestful/Dockerfile
2025-12-13 21:58:17 +01:00

46 líneas
968 B
Docker

# Build stage
FROM eclipse-temurin:21-jdk-alpine AS build
WORKDIR /app
# Copy maven wrapper and pom.xml
COPY mvnw .
COPY mvnw.cmd .
COPY .mvn .mvn
COPY pom.xml .
# Download dependencies
RUN chmod +x mvnw && ./mvnw dependency:go-offline -B
# Copy source code
COPY src src
# Build the application
RUN ./mvnw package -DskipTests -B
# Runtime stage
FROM eclipse-temurin:21-jre-alpine
WORKDIR /app
# Create non-root user for security
RUN addgroup -g 1001 -S appgroup && \
adduser -u 1001 -S appuser -G appgroup
# Copy the built artifact from build stage
COPY --from=build /app/target/*.war app.war
# Change ownership
RUN chown -R appuser:appgroup /app
# Switch to non-root user
USER appuser
# Expose port
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=60s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/api/customers || exit 1
# Run the application
ENTRYPOINT ["java", "-jar", "app.war"]