Created
February 8, 2024 11:47
-
-
Save Fanreza/3f8e8d830d707757abe14476a912be13 to your computer and use it in GitHub Desktop.
Nuxt dockerfile with multi stage build and distorless image for less bundle size
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
# Use a large Node.js base image to build the application and name it "build" | |
FROM node:18-alpine as build | |
WORKDIR /app | |
# Copy the package.json and package-lock.json files into the working directory before copying the rest of the files | |
# This will cache the dependencies and speed up subsequent builds if the dependencies don't change | |
COPY package*.json /app | |
# You might want to use yarn or pnpm instead | |
RUN npm install | |
COPY . /app | |
RUN npm run build | |
# Instead of using a node:18-alpine image, we are using a distroless image. These are provided by google: https://github.com/GoogleContainerTools/distroless | |
FROM gcr.io/distroless/nodejs:18 as prod | |
WORKDIR /app | |
# Copy the built application from the "build" image into the "prod" image | |
COPY --from=build /app/.output /app/.output | |
# Since this image only contains node.js, we do not need to specify the node command and simply pass the path to the index.mjs file! | |
CMD ["/app/.output/server/index.mjs"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment