Skip to content

Instantly share code, notes, and snippets.

@dalenguyen
Last active October 12, 2018 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dalenguyen/be47d51153284035b32ebdaebb4cc191 to your computer and use it in GitHub Desktop.
Save dalenguyen/be47d51153284035b32ebdaebb4cc191 to your computer and use it in GitHub Desktop.
Dockerfile from a Node project
# I'm using NODE 6, you can change to NODE 8 or 10
FROM node:6
# This will be the current working dir
WORKDIR /usr/src/app
# I copy entire project to the working dir
COPY . .
# Root commands
# Install sudo, vim to make changes for your project files
# Bower for install old packages - you may not need it
# Change root password to Docker!@
# Add user name admin to run command without root
# If you don't want to add custom user, just use the default node user:
# USER node instead of USER admin
# Change folders' owner to admin
RUN apt-get update \
&& apt-get install sudo -y \
&& apt-get install vim -y \
&& npm install -g bower \
&& mkdir /home/admin \
&& echo "root:Docker!@" | chpasswd \
&& useradd admin && echo "admin:admin" | chpasswd && adduser admin sudo \
&& chown -R admin:admin /home/admin \
&& chown -R admin:admin /usr/src/app
# Run project under user admin
USER admin
# Install bower packages
RUN bower install
# Install node packages
RUN npm install
# Open port for communication
EXPOSE 3000
# This will run the project when starts a container
CMD ./node_modules/gulp/bin/gulp.js serve
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment