Spaces:
Runtime error
Runtime error
# Use Node.js 18 base image | |
FROM node:18 | |
# Set environment variables for user and password | |
ENV USER=myuser | |
ENV PASSWORD=mypassword | |
# Set the working directory inside the container | |
WORKDIR /app | |
# Create a non-root user to run the application | |
RUN useradd --create-home --shell /bin/bash appuser | |
# Clone the repository | |
RUN git clone https://github.com/ChrisCindy/node-web-console.git . | |
# Install dependencies | |
RUN npm install | |
# Modify the config/index.js file while still root (to avoid permission issues) | |
RUN sed -i "s/YOUR_USERNAME/${USER}/" config/index.js && \ | |
sed -i "s/YOUR_PASSWORD/${PASSWORD}/" config/index.js | |
# Copy entrypoint script | |
COPY docker-entrypoint.sh /usr/local/bin/ | |
# Change permissions of the entrypoint script (before switching users) | |
RUN chmod +x /usr/local/bin/docker-entrypoint.sh | |
# Ensure the non-root user has full access to the /app directory | |
RUN chown -R appuser:appuser /app | |
# Switch to the non-root user after all modifications are made | |
USER appuser | |
# Expose the port the app runs on | |
EXPOSE 3000 | |
# Run the entrypoint script and start the web server in production mode | |
ENTRYPOINT ["docker-entrypoint.sh"] | |
CMD ["npm", "run", "prod"] | |