Skip to content

Instantly share code, notes, and snippets.

@yeboah326
Created March 31, 2025 07:59
Show Gist options
  • Save yeboah326/5b180d858c47f242d21cd541eb31ddf4 to your computer and use it in GitHub Desktop.
Save yeboah326/5b180d858c47f242d21cd541eb31ddf4 to your computer and use it in GitHub Desktop.
Dockerfile I used for some production react applications. Had some issues but it works fine and is quick plug and play solution.
# Use Node.js 18 as the base image
FROM node:18-alpine AS build
# Set working directory
WORKDIR /app
# Install Yarn
RUN apk add --no-cache yarn
# Copy package.json and yarn.lock
COPY package.json yarn.lock ./
# Install dependencies
RUN yarn install --frozen-lockfile
# Copy all files
COPY . .
# Build the app
RUN yarn build
# Create a lightweight production image
FROM alpine:3.14
# Install Node.js and Yarn
RUN apk add --no-cache nodejs yarn
# Install a simple HTTP server to serve static content
RUN yarn global add http-server
# Set working directory
WORKDIR /app
# Copy built assets from build stage
COPY --from=build /app/dist .
# Expose port 3000
EXPOSE 3000
# Start the HTTP server
CMD ["http-server", "-p", "3000", "-a", "0.0.0.0", "--proxy", "http://localhost:3000?"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment