Docker
Unless you are going the serverless route with the provider "SST" you have to dockerize your Next.js application with most of the other providers.
Code changes
The process of dockerizing your Next.js application is pretty straight forward. You basically need those two files to get started:
The standalone output mode ensures that your Next.js application is fully self contained and only the files being used are included in your Docker image.
module.exports = {
output: "standalone",
//... additional Next.js config
};
Once you have these files configured try to run docker build .
in your project root directory, to test the build of the Docker image.
Getting started is easy – scaling is not
When you have just one Docker container with your Next.js app running, all features should work as expected.
If you want to scale your application horizontally, you are going to run into problems with ISR (incremental static regeneration). The ISR cache is file based. So depending on your proxy load balancing strategy your users might get a different content state on a refresh.
To solve this issue you have to define a custom cache handler.
module.exports = {
output: "standalone",
cacheHandler: require.resolve('./cache-handler.js'),
cacheMaxMemorySize: 0, // disable default in-memory caching
//... additional Next.js config
};