dockernext.jsdockerfilepnpmpnpm-workspace

Docker build doesn't retrieve a next module


I'm trying to make a Dockerfile to generate an image of my front-end. My front-end contains several workspaces. Here is my Dockerfile :

Dockerfile.prod

FROM node:18-alpine

WORKDIR /app

RUN npm i -g pnpm

COPY package.json pnpm-lock.yaml ./

COPY apps/assigneePortal/package.json apps/assigneePortal/.env.local ./apps/assigneePortal/
COPY packages/IriseV3_front-core/package.json ./packages/IriseV3_front-core/
COPY packages/config-tailwind/package.json ./packages/config-tailwind/
COPY packages/config-typescript/package.json ./packages/config-typescript/

RUN pnpm install

COPY . .

RUN corepack enable pnpm && pnpm run build

When I run the command 'docker build -t nextjs:v1 -f Dockerfile.prod .' This generates an error on the build line :

Building 23.1s (16/16) FINISHED                                                                                                                                                 docker:desktop-linux
 => [internal] load build definition from Dockerfile.prod                                                                                          
 => => transferring dockerfile: 1.55kB
 => [internal] load metadata for docker.io/library/node:18-alpine
 => [auth] library/node:pull token for registry-1.docker.io
 => [internal] load .dockerignore
 => => transferring context: 82B
 => [ 1/11] FROM docker.io/library/node:18-alpine@sha256:02376a266c84acbf45bd19440e08e48b1c8b98037417334046029ab585de03e2
 => [internal] load build context
 => => transferring context: 189.69kB
 => CACHED [ 2/11] WORKDIR /app
 => CACHED [ 3/11] RUN npm i -g pnpm
 => [ 4/11] COPY package.json pnpm-lock.yaml ./
 => [ 5/11] COPY apps/assigneePortal/package.json apps/assigneePortal/.env.local ./apps/assigneePortal/
 => [ 6/11] COPY packages/IriseV3_front-core/package.json ./packages/IriseV3_front-core/
 => [ 7/11] COPY packages/config-tailwind/package.json ./packages/config-tailwind/
 => [ 8/11] COPY packages/config-typescript/package.json ./packages/config-typescript/
 => [ 9/11] RUN pnpm install
 => [10/11] COPY . .
 => ERROR [11/11] RUN corepack enable pnpm && pnpm run build
------
 > [11/11] RUN corepack enable pnpm && pnpm run build:
1.221 ! Corepack is about to download https://registry.npmjs.org/pnpm/-/pnpm-9.1.4.tgz
3.759
3.759 > irisev3_front@7.2.0 build /app
3.759 > turbo build
3.759
3.879
3.879 Attention:
3.879 Turborepo now collects completely anonymous telemetry regarding usage.
3.879 This information is used to shape the Turborepo roadmap and prioritize features.
3.879 You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
3.879 https://turbo.build/repo/docs/telemetry
3.879 
3.879 turbo 2.1.1
3.879
3.982 • Packages in scope: @irisev3front/core, @repo/tailwind-config, @repo/typescript-config, assigneeportal
3.982 • Running build in 4 packages
3.982 • Remote caching disabled
4.073 assigneeportal:build: cache miss, executing 44098d80807b6e1c
5.367 assigneeportal:build:
5.367 assigneeportal:build: > assigneeportal@7.2.0 build /app/apps/assigneePortal
5.367 assigneeportal:build: > next build
5.367 assigneeportal:build:
5.461 assigneeportal:build: node:internal/modules/cjs/loader:1143
5.461 assigneeportal:build:   throw err;
5.461 assigneeportal:build:   ^
5.461 assigneeportal:build:
5.461 assigneeportal:build: Error: Cannot find module '/app/apps/assigneePortal/node_modules/next/dist/bin/next'
5.461 assigneeportal:build:     at Module._resolveFilename (node:internal/modules/cjs/loader:1140:15)
5.461 assigneeportal:build:     at Module._load (node:internal/modules/cjs/loader:981:27)
5.461 assigneeportal:build:     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12)
5.461 assigneeportal:build:     at node:internal/main/run_main_module:28:49 {
5.461 assigneeportal:build:   code: 'MODULE_NOT_FOUND',
5.461 assigneeportal:build:   requireStack: []
5.461 assigneeportal:build: }
5.461 assigneeportal:build:
5.461 assigneeportal:build: Node.js v18.20.4
5.472 assigneeportal:build:  ELIFECYCLE  Command failed with exit code 1.
5.516 assigneeportal:build: ERROR: command finished with error: command (/app/apps/assigneePortal) /usr/local/bin/pnpm run build exited (1)
5.516 assigneeportal#build: command (/app/apps/assigneePortal) /usr/local/bin/pnpm run build exited (1)
5.523
5.523  Tasks:    0 successful, 1 total
5.523 Cached:    0 cached, 1 total
5.523   Time:    1.631s
5.523 Failed:    assigneeportal#build
5.523
5.529  ERROR  run failed: command  exited (1)
5.782  ELIFECYCLE  Command failed with exit code 1.
------
Dockerfile.prod:18
--------------------
  16 |     COPY . .
  17 |
  18 | >>> RUN corepack enable pnpm && pnpm run build
  19 |
  20 |
--------------------
ERROR: failed to solve: process "/bin/sh -c corepack enable pnpm && pnpm run build" did not complete successfully: exit code: 1

I first checked whether my local project contained the missing module. I have it at the error location. I guess there's a problem installing the packages and it can't install the next package correctly? Can you help me solve this problem?


Solution

  • RUN corepack enable
    RUN corepack install
    RUN pnpm install
    RUN pnpm run build