MULTISTAGE BUILD
# Stage 1: Build stage
FROM maven:3.9.1-eclipse-temurin-20 AS build
WORKDIR /app
# Copy only the pom.xml and download dependencies (cache layer)
COPY pom.xml .
RUN mvn dependency:go-offline
# Copy source code
COPY src ./src
# Build the project and package the jar (skip tests to speed up)
RUN mvn clean package -DskipTests
# Stage 2: Final stage with JRE
FROM eclipse-temurin: 20-jre
WORKDIR /app
# Copy the jar from the build stage
COPY --from=build /app/target/*.jar app.jar
EXPOSE 8080
# Run the application
CMD ["java", "-jar", "app.jar"]
PYTHON BASED
FROM python: 3.11-slim
WORKDIR /app
COPY requirements.txt.
RUN pip install requirements.txt
COPY . .
EXPOSE 5000
CMD ["python", "app.py"]
NGINX WEB APP
FROM nginx:alpine
# Set working directory to Nginx's default HTML folder
WORKDIR /usr/share/nginx/html
# Remove default Nginx HTML files
RUN rm -rf ./*
# Copy your website files into the container
COPY . .
# Expose port 80
EXPOSE 80
# Start Nginx in the foreground
CMD ["nginx", "-g", "daemon off;"]
APACHE WEB APP
FROM httpd:alpine
# Set working directory to default Apache document root
WORKDIR /usr/local/apache2/htdocs/
# Copy website files into document root
COPY . .
# Expose HTTP port
EXPOSE 80
# Run Apache in the foreground (default command)
CMD ["httpd", "-D", "FOREGROUND"]
NODE JS BASED
FROM node:20
WORKDIR /app
COPY . .
RUN npm install
EXPOSE 3000
CMD ["node", "server.js"]
JAVA BASED
# Use Maven with JDK as base image
FROM maven:3.9.6-eclipse-temurin-17
# Set working directory
WORKDIR /app
# Copy all project files
COPY . .
# Package the app using Maven (skip tests for speed)
RUN mvn package -DskipTests
# Run the application
CMD ["java", "-jar", "target/my-java-app-1.0-SNAPSHOT.jar"]