Skip to main content

Dockerfile

React

# Use Node.js 20 on the ARM64 platform (suitable for ARM-based systems like Apple Silicon)
FROM --platform=linux/arm64 node:20-alpine AS builder

# Enable Corepack and prepare pnpm for managing dependencies
RUN corepack enable && corepack prepare pnpm@latest --activate

# Set an environment variable for the API URL (used by Vite in development)
ENV VITE_API_URL=http://localhost:8080

# Set the working directory inside the container
WORKDIR /app

# Copy dependency management files (package.json and pnpm-lock.yaml) to the container
COPY package.json pnpm-lock.yaml ./

# Install project dependencies using pnpm
RUN pnpm install

# Copy the rest of the application source code to the container
COPY . .

# Expose the port that the Vite development server will use
EXPOSE 5173

# Run the development server with the --host flag to bind it to 0.0.0.0,
# making it accessible from outside the container
CMD ["pnpm", "dev", "--host"]
# Frontend Dockerfile
# Build stage
FROM node:20-alpine AS builder

# Install pnpm
RUN corepack enable && corepack prepare pnpm@latest --activate

ENV VITE_API_URL=

WORKDIR /app

# Copy package files
COPY package.json pnpm-lock.yaml ./

# Install dependencies
RUN pnpm install --frozen-lockfile

# Copy source code
COPY . .

# Build the application
RUN pnpm build

# Production stage
FROM nginx:alpine

# Copy built assets from builder
COPY --from=builder /app/dist /usr/share/nginx/html

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]

Golang

# Packager stage
FROM --platform=linux/arm64 golang:1.22.5 AS packager

WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download

# Builder stage
FROM --platform=linux/arm64 golang:1.22.5 AS builder

WORKDIR /app
COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o main .

# Runtime stage
FROM --platform=linux/arm64 debian:bullseye-slim AS runner

WORKDIR /app
COPY --from=builder /app/main .
COPY .env .env
EXPOSE 8080
CMD ["/app/main"]
# packger stage
FROM golang:1.22.5 AS packger

# Set the working directory
WORKDIR /app

# Copy go.mod and go.sum files
COPY go.mod go.sum ./

# Download Go dependencies
RUN go mod download

# Build stage
FROM golang:1.22.5 AS builder

# Set the working directory
WORKDIR /app

# Copy the source code
COPY . .

# Build the Go application
RUN CGO_ENABLED=0 GOOS=linux go build -o main ./

# Runtime stage
FROM debian:bullseye-slim AS runner

# Set the working directory
WORKDIR /app

# Copy the built binary from the builder stage
COPY --from=builder /app/main .

# Expose the application's port
EXPOSE 8080

# Run the application
CMD ["/app/main"]