Refactor Dockerfile for multi-stage build and update start script in package.json
- Introduced a multi-stage build in the Dockerfile to separate build and runtime environments. - Added environment variables for production in the runtime stage. - Updated the start script in package.json to point to the new server entry point.
This commit is contained in:
parent
733a1e9f47
commit
267e279cf2
2 changed files with 17 additions and 6 deletions
20
Dockerfile
20
Dockerfile
|
|
@ -1,11 +1,21 @@
|
|||
FROM node:22.12-bullseye
|
||||
|
||||
# --- build stage ---
|
||||
FROM node:22.12-bullseye AS build
|
||||
WORKDIR /app
|
||||
|
||||
COPY package.json yarn.lock ./
|
||||
RUN corepack enable && yarn install --frozen-lockfile
|
||||
|
||||
COPY . .
|
||||
RUN yarn build
|
||||
|
||||
CMD ["yarn", "start"]
|
||||
# --- runtime stage ---
|
||||
FROM node:22.12-bullseye AS runner
|
||||
WORKDIR /app
|
||||
ENV NODE_ENV=production \
|
||||
NITRO_HOST=0.0.0.0 \
|
||||
NITRO_PORT=3000 \
|
||||
HOST=0.0.0.0 \
|
||||
PORT=3000
|
||||
COPY --from=build /app/.output ./.output
|
||||
# (Optional) copy any public/static if you need it at runtime:
|
||||
# COPY --from=build /app/public ./public
|
||||
EXPOSE 3000
|
||||
CMD ["node", ".output/server/index.mjs"]
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@
|
|||
"dev": "nuxt dev",
|
||||
"generate": "nuxt generate",
|
||||
"preview": "nuxt preview",
|
||||
"postinstall": "nuxt prepare"
|
||||
"postinstall": "nuxt prepare",
|
||||
"start": "node .output/server/index.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"mongodb": "^6.18.0",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue