获取错误:NX无法创建目录:/app/node_modules/.创建Docker镜像时缓存/nx

7lrncoxx  于 2023-04-29  发布在  Docker
关注(0)|答案(1)|浏览(172)

我试图dockerize monorepo与NXNEXTJS和“NESTJS应用程序,尝试了下面的

Dockerfile。前端-

# Install deps and build the source code only when needed
FROM node:lts-alpine AS builder
RUN apk add --no-cache libc6-compat

WORKDIR /app

COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile

COPY . .

# RUN yarn nx run frontend:build:production --skip-nx-cache
RUN yarn nx run frontend:build:production -skip-nx-cache

# Production image, copy all the files and run next
FROM node:lts-alpine AS runner
WORKDIR /app

ENV NODE_ENV production

RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001

COPY --from=builder /app/dist/apps/frontend/package.json ./
RUN yarn install --ignore-scripts

# You only need to copy next.config.js if you are NOT using the default configuration
# COPY --from=builder /app/dist/apps/withlib/next.config.js ./
# COPY --from=builder /app/dist/apps/withlib/public ./public
COPY --from=builder /app/dist/apps/frontend/ ./

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/dist/apps/frontend/.next ./.next

USER nextjs
EXPOSE 7000

CMD ["npm", "start"]

但我无法运行package.json中提到的npm start-

"scripts": {
    "start": "nx serve",
    "build": "nx build",
    "test": "nx test"
  },

获取错误-在容器和网络创建后为-***〉NX无法创建目录:/app/node_modules/.运行nx serve时缓存/nx***。
有人能告诉我哪里做错了操作吗?

qqrboqgw

qqrboqgw1#

您是否试图在Kubernetes或使docker文件系统只读的环境中运行此操作?可能这就是问题所在。要绕过它(如果你在kubernetes中运行),在nx缓存位置创建一个卷/挂载。这应该能让它运转起来

相关问题