Skip to main content

Dockerfile

React

# Use an official Node.js runtime as the base image
FROM node:14

# Set the working directory inside the container
WORKDIR /app

# Copy package.json and package-lock.json to the container
COPY package*.json ./

# Install Node.js dependencies
RUN pnpm install

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

# Expose a port that the application will listen on
EXPOSE 3000

# Define the command to run your Node.js application
CMD ["pnpm", "dev"]
# 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

# Build stage
FROM golang:1.22.5 AS builder

WORKDIR /app

COPY . ./

RUN go mod download

RUN go build -o /bin/app

FROM debian:buster-slim

COPY --from=build /bin/app /bin

EXPOSE 8080

CMD [ "/bin/app" ]
# Build stage
FROM golang:1.22.5 AS builder

# 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

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