Created
April 17, 2023 04:06
-
-
Save axmad386/a0effe556aa7fbffbc7aa32c1e47581d to your computer and use it in GitHub Desktop.
Dockerfile example for optimized nodejs production
This file contains 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
FROM alpine:edge AS base | |
# install node | |
RUN apk add --no-cache nodejs npm tini | |
# set working directory | |
WORKDIR /var/www | |
#install pnpm | |
RUN npm install -g pnpm | |
# Set tini as entrypoint | |
ENTRYPOINT ["/sbin/tini", "--"] | |
# copy project file | |
COPY package.json . | |
COPY pnpm-lock.yaml . | |
# ---- Build App ---- | |
FROM base AS build | |
# install node packages | |
RUN pnpm i --production | |
# copy production node_modules aside | |
RUN cp -R node_modules prod_node_modules | |
# install ALL node_modules, including 'devDependencies' | |
RUN pnpm i | |
# build lunox | |
COPY . . | |
# COPY .env.example .env | |
RUN pnpm run build | |
# ---- Release ---- | |
FROM base AS release | |
# copy app config | |
COPY .env.example .env | |
# copy production node_modules | |
COPY --from=build /var/www/prod_node_modules node_modules | |
# copy app dist build | |
COPY --from=build /var/www/dist dist | |
# expose port and define CMD | |
EXPOSE 8000 | |
CMD npm run serve |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment