Update Dockerfile-web-ui-dev to use Node 18.16.0 and Alpine 3.17.2

This commit is contained in:
2025-02-02 18:36:23 +07:00
parent 2ffd73a012
commit 6d770469de
2 changed files with 56 additions and 33 deletions

View File

@@ -1,39 +1,38 @@
# Use an official Node.js runtime as a parent image # Use an official Node.js image as the base
FROM node:18 FROM node:18-alpine
# Set the working directory inside the container # Set the working directory in the container
WORKDIR /app WORKDIR /app
# Set environment variable to skip Chromium download
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
# Install xsel for clipboard access (useful for some applications) # Install git and Python
RUN apt-get update && apt-get install -y xsel RUN apk update && apk add --no-cache git python3 make g++
# Copy only package.json and package-lock.json (or yarn.lock) initially # Create a symlink for python3 as python
# This takes advantage of cached Docker layers RUN ln -sf /usr/bin/python3 /usr/bin/python
# Copy package.json and package-lock.json to the container
COPY package*.json ./ COPY package*.json ./
# Install dependencies # Install dependencies with the --legacy-peer-deps flag to bypass peer dependency conflicts
# npm ci is used instead of npm install when you want a clean, exact installation RUN npm install --legacy-peer-deps
#RUN npm ci --verbose
# Try to install dependencies with a retry mechanism
#RUN for i in 1 2 3; do npm ci --verbose && break || sleep 15; done
# Copy the rest of your application code # Copy the rest of the app's source code to the container
COPY . . COPY . .
# Set necessary environment variables (if they are not secrets) # Build the app
ENV NODE_ENV=development RUN npm run build
ENV VITE_API_URL_LOCAL=https://localhost:5001
ENV VITE_API_URL_SERVER=https://localhost
# Expose port 3000 for the application # Use NGINX as the web server
EXPOSE 3000 FROM nginx:alpine
# Install global dependencies if absolutely necessary (generally not recommended to do globally) # Copy the built app to the NGINX web server directory
RUN npm install -g serve vite COPY --from=0 /app/build /usr/share/nginx/html
# Build the application # Expose port 80 for the NGINX web server
RUN node --max-old-space-size=4096 node_modules/.bin/vite build EXPOSE 80
# Command to run the application # Start the NGINX web server
CMD ["npm", "run", "serve"] CMD ["nginx", "-g", "daemon off;"]

View File

@@ -1,14 +1,38 @@
FROM node:18-alpine3.17 as build # Use an official Node.js image as the base
FROM node:18-alpine
# Set the working directory in the container
WORKDIR /app WORKDIR /app
COPY . /app
RUN npm install # Set environment variable to skip Chromium download
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
# Install git and Python
RUN apk update && apk add --no-cache git python3 make g++
# Create a symlink for python3 as python
RUN ln -sf /usr/bin/python3 /usr/bin/python
# Copy package.json and package-lock.json to the container
COPY package*.json ./
# Install dependencies with the --legacy-peer-deps flag to bypass peer dependency conflicts
RUN npm install --legacy-peer-deps
# Copy the rest of the app's source code to the container
COPY . .
# Build the app
RUN npm run build RUN npm run build
FROM ubuntu # Use NGINX as the web server
RUN apt-get update FROM nginx:alpine
RUN apt-get install nginx -y
COPY --from=build /app/dist /var/www/html/ # Copy the built app to the NGINX web server directory
COPY --from=0 /app/build /usr/share/nginx/html
# Expose port 80 for the NGINX web server
EXPOSE 80 EXPOSE 80
# Start the NGINX web server
CMD ["nginx", "-g", "daemon off;"] CMD ["nginx", "-g", "daemon off;"]