我试图dockerize monorepo与NX
,NEXTJS
和“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***。
有人能告诉我哪里做错了操作吗?
1条答案
按热度按时间qqrboqgw1#
您是否试图在Kubernetes或使docker文件系统只读的环境中运行此操作?可能这就是问题所在。要绕过它(如果你在kubernetes中运行),在nx缓存位置创建一个卷/挂载。这应该能让它运转起来