Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gjerokrsteski/43e4c6d5763d6fe166eb7f3e5e4222c8 to your computer and use it in GitHub Desktop.
Save gjerokrsteski/43e4c6d5763d6fe166eb7f3e5e4222c8 to your computer and use it in GitHub Desktop.
Dockerfile with multi-stage build for dev and production
FROM node:12-alpine as base
WORKDIR /src
COPY package.json package-lock.json /src/
COPY . /src
EXPOSE 8080
FROM base as production
ENV NODE_ENV=production
RUN npm install --production
CMD ["node", "index.js"]
FROM base as dev
ENV NODE_ENV=development
RUN npm config set unsafe-perm true && npm install -g nodemon
RUN npm install
CMD ["npm", "start"]
@gjerokrsteski
Copy link
Author

Run the following commands to build the dev and the production images:

docker build . -t api-dev --target=dev
docker build . -t api-prod --target=production

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment