Creating a custom deployment setup for Next.js apps
We are now going to learn how to set up a custom deployment for Next.js apps using Docker. We have already learned the basics of deploying apps using Docker in Chapter 5, so please refer to that chapter if anything is unclear, or if you need a refresher on Docker. Let’s get started setting up our Next.js app for a Docker deployment now:
- First, we need to change the output format for Next.js to
standalone
. This option tells Next.js to create a.next/standalone
folder that only contains the necessary files for a production deployment, including only the necessarynode_modules
. This folder can then be deployed without having to installnode_modules
again. Editnext.config.mjs
and adjust the config, as follows:/** @type {import('next').NextConfig} */ const nextConfig = { output: 'standalone', } export default nextConfig
- Now, we create a
.dockerignore
file to ignore certain files that should...