Next.js Discord

Discord Forum

how to use docker with turborepo and pnpm workspaces ?

Unanswered
Polish posted this in #help-forum
Open in Discord
PolishOP
Hi, I have a monorepo with 3 next apps in my apps folder and with some packages in my packagesfolder but I don't understand how to create my dockerfile to make it work. I've tried this (from there https://github.com/vercel/turbo/tree/main/examples/with-docker but with pnpm instead of yarn):
FROM node:18-alpine AS base

FROM base AS builder

RUN apk add --no-cache libc6-compat
RUN apk update
# Set working directory
WORKDIR /app
RUN npm i -g turbo
COPY . .
RUN turbo prune --scope=my-100 --docker

# Add lockfile and package.json's of isolated subworkspace
FROM base AS installer
RUN apk add --no-cache libc6-compat
RUN apk update
WORKDIR /app

# First install the dependencies (as they change less often)
COPY .gitignore .gitignore
COPY --from=builder /app/out/json/ .
COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
RUN npm i -g pnpm
RUN pnpm install

# Build the project
COPY --from=builder /app/out/full/ .
COPY turbo.json turbo.json

RUN pnpm turbo run build --filter=my-100...

FROM base AS runner
WORKDIR /app

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
USER nextjs

COPY --from=installer /app/apps/my-100/next.config.js .
COPY --from=installer /app/apps/my-100/package.json .

COPY --from=installer --chown=nextjs:nodejs /app/apps/my-100/.next/standalone ./
COPY --from=installer --chown=nextjs:nodejs /app/apps/my-100/.next/static ./apps/my-100/.next/static
COPY --from=installer --chown=nextjs:nodejs /app/apps/my-100/public ./apps/my-100/public

CMD node apps/my-100/server.js


Does anyone have a suggestion for me please?

2 Replies

PolishOP
but it does not work and I get an error :
 => ERROR [installer 12/14] COPY --from=builder /app/out/full/ .                                                                              0.9s
------
 > [installer 12/14] COPY --from=builder /app/out/full/ .:
------
failed to solve: rpc error: code = Unknown desc = cannot copy to non-directory: /var/lib/docker/overlay2/a257w9vmkbn0nwaoqfxztvmf3/merged/app/apps/my-100/node_modules/@cid/core
Burmese
seems like you are copying your local node_modules to your docker image
make sure your .dockerignore contains **/node_modules