refactor: optimize Docker deployment with standalone mode

- Enable Next.js standalone output for smaller image size
- Remove unnecessary npm install in production stage
- Use direct node execution instead of npm start
- Add .dockerignore to exclude unnecessary files from build context
This commit is contained in:
xmanrui
2026-03-03 17:01:24 +08:00
parent f0bbd81763
commit c064d7f8c4
3 changed files with 15 additions and 4 deletions
+10
View File
@@ -0,0 +1,10 @@
node_modules
.next
.git
.gitignore
.claude
*.md
.env*.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*
+2 -3
View File
@@ -13,8 +13,7 @@ WORKDIR /app
ENV NODE_ENV=production ENV NODE_ENV=production
RUN npm install next --save # Copy standalone output
COPY --from=builder /app/.next/standalone ./ COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/public ./public COPY --from=builder /app/public ./public
@@ -24,4 +23,4 @@ EXPOSE 3000
ENV PORT=3000 ENV PORT=3000
ENV HOSTNAME="0.0.0.0" ENV HOSTNAME="0.0.0.0"
CMD ["npm", "start"] CMD ["node", "server.js"]
+3 -1
View File
@@ -1,3 +1,5 @@
/** @type {import('next').NextConfig} */ /** @type {import('next').NextConfig} */
const nextConfig = {}; const nextConfig = {
output: 'standalone',
};
export default nextConfig; export default nextConfig;