# Use the official Node.js 18 image as the base | |
FROM node:18 | |
# Set working directory | |
WORKDIR /app | |
# Create a new user with a unique UID and switch to it | |
RUN useradd -m -u 1001 user | |
# Switch to root user to install dependencies | |
USER root | |
# Copy package.json and package-lock.json first (for efficient caching) | |
COPY --chown=user ./package.json ./package-lock.json ./ | |
# Install dependencies (including dev dependencies) | |
RUN npm install --no-cache | |
# Copy the rest of the application files | |
COPY --chown=user . . | |
# Switch back to non-root user | |
USER user | |
# Expose the port the app runs on | |
EXPOSE 3001 | |
# Start the development server | |
CMD ["npm", "run", "dev"] | |