Skip to content

Instantly share code, notes, and snippets.

@coderdiaz
Created March 16, 2025 00:54
Show Gist options
  • Save coderdiaz/b756fb1dae938e2e7e467bc93f1d020e to your computer and use it in GitHub Desktop.
Save coderdiaz/b756fb1dae938e2e7e467bc93f1d020e to your computer and use it in GitHub Desktop.
Dockerfile Example
# Creating multi-stage build for production
FROM node:18-alpine3.18 as build
RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev vips-dev > /dev/null 2>&1
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /opt/
COPY package.json yarn.lock ./
RUN yarn config set network-timeout 600000 -g && yarn install --production
ENV PATH /opt/node_modules/.bin:$PATH
WORKDIR /opt/app
COPY . .
RUN yarn build
# Creating final production image
FROM node:18-alpine3.18
RUN apk add --no-cache vips-dev
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /opt/
COPY --from=build /opt/node_modules ./node_modules
WORKDIR /opt/app
COPY --from=build /opt/app ./
ENV PATH /opt/node_modules/.bin:$PATH
RUN chown -R node:node /opt/app
USER node
EXPOSE 1337
CMD ["yarn", "start"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment