-
Notifications
You must be signed in to change notification settings - Fork 60.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add docker deployment support #39
Conversation
Someone is attempting to deploy a commit to a Personal Account owned by @Yidadaa on Vercel. @Yidadaa first needs to authorize it. |
分阶段构建减小镜像体积可以参考官方例子next.js example
const nextConfig = {
experimental: {
appDir: true,
},
output: 'standalone',
webpack(config) {
config.module.rules.push({
test: /\.svg$/,
use: ["@svgr/webpack"],
}); // 针对 SVG 的处理规则
return config;
}
}; DockerfileFROM node:18-alpine AS base
# Install dependencies only when needed
FROM base AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app
# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi
# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
# ENV NEXT_TELEMETRY_DISABLED 1
RUN yarn build
# If using npm comment out above and use below instead
# RUN npm run build
# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app
ENV NODE_ENV production
# Uncomment the following line in case you want to disable telemetry during runtime.
# ENV NEXT_TELEMETRY_DISABLED 1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
COPY --from=builder /app/public ./public
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
EXPOSE 3000
ENV PORT 3000
CMD ["node", "server.js"]
构建运行docker build -t nextjs-docker .
docker run -p 3000:3000 nextjs-docker |
尝试了,但出现构建错误,对于使用了 |
Docker 镜像已发布, |
感谢,我今晚验证后会合并此 PR。 |
应该是缺少git |
你应该自己发布 |
@Chanzhaoyu 我会引入一个 github action 来自动发布。 |
是的 |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Error: ' can be escaped with ', ‘, &ChatGPTNextWeb#39;, ’. react/no-unescaped-entities。 这个错误是由于React中的JSX语法不支持非转义的特殊字符,如 ' 等。解决这个错误的方法是将特殊字符转义为HTML实体,如 '、‘ 或 &ChatGPTNextWeb#39;。 ‘ ---> '
feat: add docker deployment support
使用 Docker 构建本项目
Todo