FROM node:10-stretch-slim # Set an environment variable to store where the app is installed to inside of the Docker image. ENV WORKSPACE /app RUN mkdir -p $WORKSPACE # Change WORKSPACE owner RUN chown -R node:node $WORKSPACE # Change running user USER node # This sets the context of where commands will be ran in and is documented # on Docker's website extensively. # Set app directory WORKDIR $WORKSPACE # Install app dependencies # A wildcard is used to ensure both package.json AND package-lock.json are copied # where available (npm@5+) COPY --chown=node:node package.json . COPY --chown=node:node yarn.lock . RUN yarn install --frozen-lockfile --silent --non-interactive # If you are building your code for production # RUN yarn install --production --frozen-lockfile --silent --non-interactive # Bundle app source COPY --chown=node:node . . EXPOSE 3000 CMD [ "yarn", "start" ]