docker run的时候rror: ENOENT: no such file or directory, open '/app/.next/BUILD_ID’

189 阅读1分钟

docker run之后查看logs

image.png

说没有/app/.next/BUILD_ID这个目录

参考Error: ENOENT: no such file or directory, open '.next/BUILD_ID' when deploying on Vercel · vercel/next.js · Discussion #17142

image.png 说是.next不存在 尝试在启动容器的时候创建.next docker run -d \ --name gdst_dex \ -v /home/xxx:/app \ -v xxx:/app/.next \ -p 18886:3000 \ xxx sh -c "cd /app && npm install && npm run build && npm run start"

image.png

检查容器内的next目录 docker exec gdst_dex ls -la /app/.next

image.png 没有build之后的文件(BUILD_ID, build-manifest.json..)所以.next确实是空的 进入容器之后重新build docker exec gdst_dex sh -c "cd /app && npm run build" 报错

image.png 重新下载autoprefixer docker exec gdst_dex sh -c "cd /app && npm install autoprefixer postcss tailwindcss" 没用,尝试在本地build,移除了在page页面导出的组件,build 成功 然后push到服务器 还是报上图找不到autoprefixer的错,尝试将autoprefixer写在dependencies而不是devDependencies还是一样的错误 解决方法:指定node版本为18,而不是最新的版本

FROM docker.m.daocloud.io/node:18-alpine

RUN apk add --no-cache libc6-compat git

# Set working directory
WORKDIR /app

# Copy package files
COPY package*.json ./

# Install dependencies with specific npm version
RUN npm install --registry=https://registry.npmmirror.com/

# Copy the rest of the application
COPY . .

# Set production environment
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1

# Build the application and verify the build
RUN npm run build && \
    ls -la .next && \
    echo "Build completed successfully"

EXPOSE 3000

# Start the application in production mode
CMD ["npm", "run", "start"]