Last active
April 15, 2020 02:15
-
-
Save crizstian/949db22fea630ae4cc4149ae5e6b0657 to your computer and use it in GitHub Desktop.
Example of Dockerfile for a nodejs app
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
# the first thing we specify in a Dockerfile is the base image. | |
# This is essentially bare bones alpine linux with node installed. | |
FROM node:7.5.0-alpine | |
# Creates a non-root-user. | |
RUN addgroup -S nupp && adduser -S -g nupp nupp | |
# Sets the HOME environment variable. | |
ENV HOME=/home/nupp | |
# Copy the files specified, in the 'app' folder. | |
COPY package.json npm-shrinkwrap.json $HOME/app/ | |
# Copy our src code, in the 'app/src' folder. | |
COPY src/ $HOME/app/src | |
# Add dumb-init to our alpine linux. | |
ADD https://github.com/Yelp/dumb-init/releases/download/v1.1.1/dumb-init_1.1.1_amd64 /usr/local/bin/dumb-init | |
WORKDIR $HOME/app | |
# Executes some bash commands and installs our project dependencies. | |
RUN chown -R nupp:nupp $HOME/* /usr/local/ && \ | |
chmod +x /usr/local/bin/dumb-init && \ | |
npm cache clean && \ | |
npm install --silent --progress=false --production && \ | |
chown -R nupp:nupp $HOME/* | |
# Changes the root user to a non-root-user for security. | |
USER nupp | |
# Expose our server port. | |
EXPOSE 3000 | |
# the CMD command tells docker that this image should run the node executable. | |
# When the executable terminates, the container shuts down. | |
CMD ["dumb-init", "npm", "start"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment