Last active
September 28, 2021 08:32
-
-
Save alanhortz/355e516abaca3adfd14db4d6bfdd7a0a to your computer and use it in GitHub Desktop.
Node.js - Production Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Node.js Production Dockerfile | |
FROM node:14-alpine | |
# Update the system | |
RUN apk --no-cache -U upgrade | |
# Alpine comes with a non-root user called 'node' with a home directory at /home/node | |
# Prepare destination directory and ensure user node owns it | |
RUN mkdir -p /home/node/app && chown -R node:node /home/node/app | |
# Set CWD | |
WORKDIR /home/node/app | |
# Install PM2 | |
RUN npm i -g pm2 | |
# Copy package.json, package-lock.json and process.yml | |
COPY package*.json process.yml ./ | |
# Switch to user node | |
USER node | |
RUN npm i --only=production | |
COPY . . | |
ARG PORT | |
ENV PORT=${PORT:-3000} | |
#EXPOSE ${PORT} | |
# Use PM2 to run the application as stated in config file | |
ENTRYPOINT ["pm2-runtime", "./process.yml"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment