Skip to content

Instantly share code, notes, and snippets.

@mdrobny
Created September 15, 2021 17:23
Show Gist options
  • Select an option

  • Save mdrobny/d674d3a84209ac86dca3ad3b5edd78e6 to your computer and use it in GitHub Desktop.

Select an option

Save mdrobny/d674d3a84209ac86dca3ad3b5edd78e6 to your computer and use it in GitHub Desktop.
Dockerfile with TS
FROM node:14-alpine as builder
WORKDIR /app
COPY package*.json .npmrc ./
# installing deps is separate from copying source to reuse image with deps if none changed
RUN npm ci
COPY tsconfig*.json ./
COPY src ./src
COPY config ./config
# Compile TS to JS
RUN npm run build
# Remove devDependecies
RUN npm prune --production
# Move required files to final dir
RUN mv package.json ./node_modules ./dist
# resulting image
FROM node:14-alpine
WORKDIR /app
COPY --from=builder /app/dist ./
EXPOSE 8080
CMD ["/usr/local/bin/npm", "start"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment