Skip to content
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

Improve documentation for usage with Docker #79

Open
william-abboud opened this issue Sep 27, 2024 · 2 comments
Open

Improve documentation for usage with Docker #79

william-abboud opened this issue Sep 27, 2024 · 2 comments

Comments

@william-abboud
Copy link

william-abboud commented Sep 27, 2024

After struggling for a few hours I finally got next-logger and pino to work within Docker but the docs here need to be improved. I hope by raising this issue it saves people time. Here are the necessary steps I took in order to get it to work correctly.

  1. Make sure next-logger.config.js file is located in the root of the project (alongside package.json for example)
  2. Add NEXT_RUNTIME=nodejs ENV variable in Docker - Since next-logger is required in instrumentation.ts|js file typically the library will only be loaded if the runtime is nodejs. This variable is set by Vercel automatically but if you are not deploying on Vercel you have to do it manually.
// instrumentation.ts file
export async function register() {
  if (process.env.NEXT_RUNTIME === "nodejs") {
    await require("pino");
    await require("next-logger");
  }
}
// Dockerfile
ENV NEXT_RUNTIME=nodejs
  1. Add next-logger and pino to serverComponentsExternalPackages property in Next configuration -
// next.config.js
...
experimental {
  ...
  serverComponentsExternalPackages: [
    'next-logger',
    'pino',
  ],
  ...
}
  1. Copy the next-logger.config.js file from the root of the project and place it in the runtime image in the same folder as server.js. Thank you: Additional fields not showing in the log object #26 (comment) for this
// Dockerfile
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
# Copy the next-logger.config.js
COPY --from=builder /app/next-logger.config.js ./

Thank you to all the developers making this project!

@lah-wag
Copy link

lah-wag commented Nov 6, 2024

I'm on next 14, and I can' get serverComponentsExternalPackages to work.

Do you need to copy next-logger and pino from node_modules into the resulting Docker-container for this to work?

COPY --from=deps --chown=nextjs:nodejs /node_modules/pino ./

Or similar.

@william-abboud
Copy link
Author

I do copy the whole of the node_modules:

COPY --from=deps /app/node_modules ./node_modules

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants