0% found this document useful (0 votes)
47 views3 pages

Docker File

The document outlines various Dockerfile configurations for building applications in different programming environments including Java, Python, Nginx, Apache, and Node.js. Each section specifies the base image, working directory, file copying, dependency installation, port exposure, and command to run the application. It emphasizes efficient build processes, such as skipping tests to speed up the packaging stage.

Uploaded by

Pooja A S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views3 pages

Docker File

The document outlines various Dockerfile configurations for building applications in different programming environments including Java, Python, Nginx, Apache, and Node.js. Each section specifies the base image, working directory, file copying, dependency installation, port exposure, and command to run the application. It emphasizes efficient build processes, such as skipping tests to speed up the packaging stage.

Uploaded by

Pooja A S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

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"]

You might also like