Unverified Commit ca8fd316 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Update docker image to leverage output traces (#32258)

This updates our docker example to leverage the output traces and standalone build to reduce the resulting docker image quite a bit. 

docker image size before: `272MB`
docker image size after: `121MB`
node-14:alpine size (base image): `118MB`

## Documentation / Examples

- [x] Make sure the linting passes by running `yarn lint`

x-ref: https://github.com/vercel/next.js/pull/32255
x-ref: https://github.com/vercel/next.js/issues/32252
x-ref: https://github.com/vercel/next.js/issues/30822
parent 438ee961
...@@ -25,10 +25,13 @@ RUN adduser -S nextjs -u 1001 ...@@ -25,10 +25,13 @@ RUN adduser -S nextjs -u 1001
# You only need to copy next.config.js if you are NOT using the default configuration # You only need to copy next.config.js if you are NOT using the default configuration
# COPY --from=builder /app/next.config.js ./ # COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/public ./public COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json COPY --from=builder /app/package.json ./package.json
# 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 USER nextjs
EXPOSE 3000 EXPOSE 3000
...@@ -40,4 +43,4 @@ ENV PORT 3000 ...@@ -40,4 +43,4 @@ ENV PORT 3000
# Uncomment the following line in case you want to disable telemetry. # Uncomment the following line in case you want to disable telemetry.
# ENV NEXT_TELEMETRY_DISABLED 1 # ENV NEXT_TELEMETRY_DISABLED 1
CMD ["node_modules/.bin/next", "start"] CMD ["node", "server.js"]
module.exports = {
experimental: {
outputStandalone: true,
},
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment