Created
March 1, 2025 06:14
-
-
Save blackestwhite/9920ac986ea81518c7265e7f1fa26d42 to your computer and use it in GitHub Desktop.
nuxt dockerfile
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
FROM node:23-alpine3.20 AS build | |
# update and install the latest dependencies for the alpine version | |
RUN apk update && apk upgrade | |
# Install pnpm | |
RUN corepack enable && corepack prepare pnpm@latest --activate | |
# set work dir as app | |
WORKDIR /app | |
# copy the nuxt project package json and package json lock if available | |
COPY package* ./ | |
# install all the project dependencies with pnpm | |
RUN pnpm install | |
# copy all other project files to working directory | |
COPY . ./ | |
# build the nuxt project with pnpm | |
RUN pnpm run build | |
# we are using multi stage build process to keep the image size as small as possible | |
FROM node:23-alpine3.20 | |
# update and install latest dependencies, add dumb-init package | |
# add a non root user | |
RUN apk update && apk upgrade && apk add dumb-init && adduser -D nuxtuser | |
# set non root user | |
USER nuxtuser | |
# set work dir as app | |
WORKDIR /app | |
# copy the output directory to the /app directory from | |
# build stage with proper permissions for user nuxt user | |
COPY --chown=nuxtuser:nuxtuser --from=build /app/.output ./ | |
# expose 3000 on container | |
EXPOSE 3000 | |
# set app host and port . In nuxt 3 this is based on nitro and you can read | |
#more on this https://nitro.unjs.io/deploy/node#environment-variables | |
ENV HOST=0.0.0.0 PORT=3000 NODE_ENV=production | |
# start the app with dumb init to spawn the Node.js runtime process | |
# with signal support | |
CMD ["dumb-init","node","/app/server/index.mjs"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment