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
This commit is contained in:
JJ Kasper 2021-12-13 07:11:12 -06:00 committed by GitHub
parent 438ee9618f
commit ca8fd316f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View file

@ -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
# COPY --from=builder /app/next.config.js ./
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
# 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
@ -40,4 +43,4 @@ ENV PORT 3000
# Uncomment the following line in case you want to disable telemetry.
# ENV NEXT_TELEMETRY_DISABLED 1
CMD ["node_modules/.bin/next", "start"]
CMD ["node", "server.js"]

View file

@ -0,0 +1,5 @@
module.exports = {
experimental: {
outputStandalone: true,
},
}