It seems like you're experiencing an issue with hot reloading in a Docker environment with Next.js. This is a known issue and there are several ways to address it.
One solution is to add environment variables to your Dockerfile. This was suggested by a user in a Github issue (https://github.com/vercel/next.js/issues/36774) related to hot reloading in Docker. The user added the following environment variables to their Dockerfile:
ENV NODE_ENV=development
ENV CHOKIDAR_USEPOLLING=true
ENV WATCHPACK_POLLING=true
Another user suggested modifying the next.config.js file to enable polling:
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
webpack: (config, context) => {
if(process.env.NEXT_WEBPACK_USEPOLLING) {
config.watchOptions = {
poll: 500,
aggregateTimeout: 300
}
}
return config
},
}
module.exports = nextConfig
In this case, you would need to set the NEXT_WEBPACK_USEPOLLING environment variable in your Docker environment.
Another user in the same Github issue (https://github.com/vercel/next.js/issues/36774) mentioned that the issue was not with Next.js or Docker, but with the Docker host. They suggested using inotify mount if you're using colima.
Please note that these solutions might slow down the compilation process.
If you're using NGINX with Docker, you might need to add some configuration to handle WebSocket connections, as suggested in another Github issue (https://github.com/vercel/next.js/issues/63203). The user added the following to their NGINX configuration: