Last active
March 20, 2021 13:30
-
-
Save alsotang/9f8cd47480cf4ac87b3ff3f101fb1906 to your computer and use it in GitHub Desktop.
Dockerfile for typescript project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use the official lightweight Node.js lts image. | |
# https://hub.docker.com/_/node | |
FROM node:lts-alpine AS build | |
# Create and change to the app directory. | |
WORKDIR /usr/src/app | |
# Copy application dependency manifests to the container image. | |
# A wildcard is used to ensure copying both package.json AND package-lock.json (when available). | |
# Copying this first prevents re-running npm install on every code change. | |
COPY package*.json ./ | |
# install deps and dev deps | |
RUN npm ci | |
# Copy local code to the container image. | |
COPY . ./ | |
# compile .ts | |
RUN npm run build | |
# slim node_modules | |
RUN npm ci --production | |
# runtime stage | |
FROM node:lts-alpine | |
# copy the dist and node_modules | |
COPY --from=build /usr/src/app /usr/src/app | |
WORKDIR /usr/src/app | |
# Run the web service on container startup. | |
CMD [ "npm", "start" ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment