Replies: 8 comments 7 replies
-
I try to change the Dockerfile to this: # Install dependencies only when needed
# FROM node:16.13-alpine AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
# RUN apk add --no-cache libc6-compat
# WORKDIR /app
# COPY package.json yarn.lock .yarnrc.yml .pnp.cjs .pnp.loader.mjs ./
# RUN echo 'YARN VERSION IN DEPS: ' && yarn --version
# Rebuild the source code only when needed
FROM node:16.13-alpine AS builder
WORKDIR /app
# COPY --from=deps /app/.yarn ./.yarn
COPY . .
RUN yarn install --immutable
RUN yarn build
# Production image, copy all the files and run next
FROM node:16.13-alpine AS runner
WORKDIR /app
ENV NODE_ENV production
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001
# You only need to copy next.config.js if you are NOT using the default configuration
COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
COPY --from=builder /app/.env.production.local ./
USER nextjs
EXPOSE 3000
ENV PORT 3000
# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry.
ENV NEXT_TELEMETRY_DISABLED 1
CMD ["node", "server.js"] But it shows error from logs when I try to run it: Error: Cannot find module 'next/dist/server/next-server'
Require stack:
- /app/server.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/app/server.js:4:20)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/app/server.js' ] |
Beta Was this translation helpful? Give feedback.
-
As far as I know Yarn 3 is still in development. The docker example focuses on Yarn 1 which based on npm version stats is wildly more popular than v2 as well (1,5 million vs ~20000 weekly downloads, only looking their latest versions). |
Beta Was this translation helpful? Give feedback.
-
@balazsorban44 I see. too bad.. my team keep complain that docker build is too slow for them.. I try to optimise the build time from docker by using yarn 3 pnp.. |
Beta Was this translation helpful? Give feedback.
-
I created a gist to deploy NextJS apps using yarn v3 and PnP with Docker. |
Beta Was this translation helpful? Give feedback.
-
Any update on this? trying with Next.js 13.1.5 and yarn 3.4.1 the issue still persists. |
Beta Was this translation helpful? Give feedback.
-
Still not fixed. Any updates on that matter? |
Beta Was this translation helpful? Give feedback.
-
Running with It looks like the ultimate solution may need to address #34600. Today, |
Beta Was this translation helpful? Give feedback.
-
Here may be a better workaround cause I found that next.config.js: /** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
output: "standalone",
// Other configuration
};
module.exports = nextConfig; .yarnrc.yml: # These configurations are generated by yarn with commands:
#
# yarn plugin import workspace-tools
# yarn set version latest
#
# You should replace 3.5.1 with the real version of your yarn,
# if you want to manually set these configurations.
plugins:
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: "@yarnpkg/plugin-workspace-tools"
yarnPath: .yarn/releases/yarn-3.5.1.cjs Dockerfile: FROM node:18-alpine AS base
ENV NODE_ENV=production
RUN corepack enable
RUN corepack prepare yarn@stable --activate
FROM base AS deps
WORKDIR /app
COPY ./package.json .
COPY ./.yarn/plugins ./.yarn/plugins
COPY ./.yarn/releases ./.yarn/releases/
COPY ./.yarnrc.yml .
RUN yarn install
FROM base AS builder
WORKDIR /app
COPY . .
COPY --from=deps /app/.yarn ./.yarn/
COPY --from=deps /app/yarn.lock .
RUN yarn build
FROM base AS runner
WORKDIR /app
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static/
COPY --from=builder /app/public ./public/
FROM runner AS production
WORKDIR /app
COPY --from=builder /app/.yarn/plugins .yarn/plugins/
COPY --from=builder /app/.yarnrc.yml .
COPY --from=builder /app/.yarn/releases .yarn/releases/
# Delete this folder cause it contains the `next` dependency which was output by Next.js builder.
# If we install dependencies later, yarn will try to rename cache file `***.tmp` to `***.zip`.
# But the name has been claimed already when it comes to `next` to be installed,
# which causes a failure of building image.
RUN rm -rf ./.yarn/cache
RUN yarn workspaces focus --all --production
USER nextjs
EXPOSE 3000
# Replace 3.5.1 with the real version of your yarn.
CMD ["node", "/app/.yarn/releases/yarn-3.5.1.cjs", "--", "node", "/app/server.js"] With this you will only install production dependencies while building docker image. |
Beta Was this translation helpful? Give feedback.
-
What is the improvement or update you wish to see?
I follow the latest docker build
next.config.js
with thisoutputStandalone
enableI had no clue what's file need to include when migrate to yarn 3 PnP
current Dockerfile:
Is there any context that might help us understand?
yarn 3 PnP with docker docs support
I am using next.js 12.0.8
Does the docs page already exist? Please link to it.
https://github.com/vercel/next.js/tree/canary/examples/with-docker
Beta Was this translation helpful? Give feedback.
All reactions