Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
NodeJS backend dockerfile
# Tooling configuration files
FROM scratch AS context
ADD package.json \
yarn.lock \
.eslintrc.js \
.eslintignore \
/workspace/
# Source code
FROM scratch AS sources
ADD src /workspace/src
# Install dependencies
FROM node:alpine AS dependencies
COPY --from=context /workspace/package.json /workspace/package.json
COPY --from=context /workspace/yarn.lock /workspace/yarn.lock
WORKDIR /workspace
RUN yarn install --network-timeout 300000 --production
# Install dev dependencies
FROM node:alpine AS dev-dependencies
COPY --from=dependencies /workspace /workspace
WORKDIR /workspace
RUN yarn install --network-timeout 300000
# Lint
FROM node:alpine AS linter
COPY --from=context /workspace /workspace
COPY --from=dev-dependencies /workspace/node_modules /workspace/node_modules
COPY --from=sources /workspace/src /workspace/src
WORKDIR /workspace
RUN yarn run lint
# Build
FROM node:alpine AS builder
COPY --from=context /workspace /workspace
COPY --from=dev-dependencies /workspace/node_modules /workspace/node_modules
COPY --from=sources /workspace/src /workspace/src
WORKDIR /workspace
RUN yarn run build
# Final artifact
FROM nginx:alpine AS runner
COPY --from=builder /workspace/dist/spa /usr/share/nginx/html
WORKDIR /workspace
ADD entrypoint.sh /workspace/entrypoint.sh
EXPOSE 8000
CMD ["/bin/sh", "/workspace/entrypoint.sh"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment