dockerizing for production
This commit is contained in:
47
Dockerfile
Normal file
47
Dockerfile
Normal file
@@ -0,0 +1,47 @@
|
||||
# Stage 1: Build the React application
|
||||
FROM node:20-alpine AS builder
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Copy package manager files for the viewer app
|
||||
COPY viewer/package.json viewer/pnpm-lock.yaml ./viewer/
|
||||
|
||||
# Install pnpm and dependencies
|
||||
RUN npm install -g pnpm
|
||||
WORKDIR /app/viewer
|
||||
RUN pnpm install --frozen-lockfile
|
||||
|
||||
# Copy the rest of the application source code
|
||||
COPY viewer/ ./
|
||||
|
||||
RUN unset VITE_API_PROXY_TARGET
|
||||
RUN unset VITE_API_PROXY_TARGET
|
||||
# Build the application. Vite will automatically use the .env file we just created.
|
||||
RUN pnpm build
|
||||
|
||||
# Stage 2: Serve the application with Nginx
|
||||
FROM nginx:1.27-alpine
|
||||
|
||||
|
||||
# Remove the default Nginx configuration
|
||||
RUN rm /etc/nginx/conf.d/default.conf
|
||||
|
||||
# Copy the build output from the builder stage to the Nginx html directory
|
||||
COPY --from=builder /app/viewer/dist /usr/share/nginx/html
|
||||
|
||||
# Copy the Nginx configuration template and the entrypoint script
|
||||
COPY nginx.conf.template /etc/nginx/templates/
|
||||
COPY docker-entrypoint.sh /
|
||||
|
||||
# Make the entrypoint script executable
|
||||
RUN chmod +x /docker-entrypoint.sh
|
||||
|
||||
# Set the entrypoint
|
||||
ENTRYPOINT ["/docker-entrypoint.sh"]
|
||||
|
||||
# Expose port 80
|
||||
EXPOSE 80
|
||||
|
||||
# Start Nginx in the foreground
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
Reference in New Issue
Block a user