Skip to content

Instantly share code, notes, and snippets.

@jeckel
Last active September 4, 2018 06:34
Show Gist options
  • Save jeckel/ba094202f1c6636a1568cd9156e155c0 to your computer and use it in GitHub Desktop.
Save jeckel/ba094202f1c6636a1568cd9156e155c0 to your computer and use it in GitHub Desktop.
Production ready nodejs Dockerfile sample
# Ignore all .files except .babelrc
.*
!.babelrc
# Ignore build directories and dependencies
# everything that will be re-generated by the install/build steps
lib
dist
node_modules
# Ignore dev configuration files
docker-compose.yml
Dockerfile
Makefile
nodemon.json
# Remove documentation
*.md
# Ignore tests files
src/**/*.test.js
test
jest.config.json
FROM node:9-alpine AS builder
LABEL maintainer="Julien MERCIER <[email protected]>"
# Build project
WORKDIR /home/node/app
COPY . .
# Build whatever you have to build (babel, grunt, webpack, etc.)
RUN npm install && \
npm run build
# Make the run container
#
FROM node:9-alpine
ENV NODE_ENV=production
WORKDIR /home/node/app
# Install deps for production only
COPY ./package* ./
RUN npm install && \
npm cache clean --force
# Copy build source from builder stage
COPY --from=builder /home/node/app/dist ./dist
CMD npm start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment