40 lines
1.0 KiB
Docker
40 lines
1.0 KiB
Docker
# Stage 1: Build the application
|
|
FROM node:20-alpine AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy package files and install dependencies
|
|
COPY package.json package-lock.json ./
|
|
RUN npm ci
|
|
|
|
# Copy the rest of the application source code
|
|
COPY . .
|
|
|
|
# Build the application for production
|
|
RUN npm run build
|
|
|
|
# Stage 2: Serve the application with a simple Node.js server
|
|
FROM node:20-alpine
|
|
|
|
WORKDIR /app
|
|
|
|
# Install a simple and lightweight HTTP server globally
|
|
RUN npm install -g http-server
|
|
|
|
# Copy the built static assets from the builder stage
|
|
COPY --from=builder /app/dist ./dist
|
|
|
|
# Copy the custom entrypoint script to the image and make it executable
|
|
COPY entrypoint.sh /docker-entrypoint.sh
|
|
RUN chmod +x /docker-entrypoint.sh
|
|
|
|
# Expose the port the server will run on, matching your compose file
|
|
EXPOSE 5174
|
|
|
|
# The entrypoint will run at container startup, performing any necessary setup.
|
|
# It should end with 'exec "$@"' to run the CMD.
|
|
ENTRYPOINT ["/docker-entrypoint.sh"]
|
|
|
|
# The CMD specifies the main process to run: the http-server.
|
|
CMD ["http-server", "dist", "-p", "5174"]
|