Optimally dockerizing NextJS application — “Runtime” environment variable configuration( Part 2 )
Before we begin
This article serves as a continuation of the previously mentioned piece on the optimal dockerization of a NextJS application, which can be found here:
If you haven’t had the chance to explore the earlier article, I highly recommend doing so. It will provide valuable insights into the implementation process and the underlying reasons for this endeavor.
Introduction
When working with NextJS, managing runtime variables can be a bit of a challenge. While the documentation provides some insight into how these variables are handled, it doesn’t explicitly explain their treatment when packaging a NextJS app in standalone mode.
Let’s take a moment to review how NextJS handles environment variables differently. Variables prefixed with NEXT_PUBLIC_*
are included in the client-side bundle. These variables are embedded at build time, making them accessible in browser bundles.
On the other hand, environment variables without the NEXT_PUBLIC_
prefix are not bundled in. This means they are not accessible in…