-
Notifications
You must be signed in to change notification settings - Fork 27k
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
Hot reload dont work when you use docker #36774
Comments
I find temporary fix Create
But after that I switch from SWC to Webpack5 (which is slow). Is there a way to run it with new faster compiler (swc)? |
In And the set an environment variable of |
@GorlikItsMe I have the same problem !
Your solution doesn't work for me 😓 |
I had the same problem and I managed to find a solution. The fix by GorlikItsMe should be adapted to the latest structure of Here is my /** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
// except for webpack, other parts are left as generated
webpack: (config, context) => {
config.watchOptions = {
poll: 1000,
aggregateTimeout: 300
}
return config
}
}
module.exports = nextConfig It seems CHOKIDAR_USEPOLLING=true is not necessary for my environment which is inside a devcontainer.
|
This works but is very very slow. |
It turns out that I reinstall my windows Docker Desktop with Hyper-v but not WSL2 solved this problem. This problem is caused by a WSL2 bug that still exists here: microsoft/WSL#4739 (comment) This way doesn't need to change the config and we can still use the SWC compiler. |
I have tried all the changes above and I still have this issue, I'm also on mac so @PaRaD1SE98 fix shouldn't affect me. Has anyone else had any luck with anything else? |
I found a better solution than #36774 (comment) Still use WSL2 version of Windows Docker Desktop, but just clone your repository in your WSL Linux |
Thanks, this worked for me. I'm using next 13.1.1 and node 18.11.18. |
Adding exact volume values worked for me.
Specify them this way:
|
next.config.js webpack: (config, context) => {
// https://webpack.kr/configuration/watch/#watchoptions
// https://github.com/vercel/next.js/issues/36774#issuecomment-1211818610
config.watchOptions = {
// default is 5007
// https://github.com/webpack/watchpack/blob/a54bcdb95759558ca5a9fc2819c4d71b771c162f/lib/DirectoryWatcher.js#L79
poll: 1000,
}
return config
} |
I set the environment variable to
|
I added the following line to my Dockerfile:
|
didn't work for me, I use docker compose, and "next": "13.2.4" |
I got it working by adding an (ignored) override file so I could have a different config for local development: # docker-compose.override.yml
services:
webapp:
command: yarn dev
environment:
NODE_ENV: development
ports:
- 3000:3000
volumes:
- ./:/app
- ./node_modules:/app/node_modules
- ./.next:/app/.next |
it was too slow. see this issue vercel/next.js#36774
Adding the following variables in Dockerfile worked for me: ENV NODE_ENV=development
ENV CHOKIDAR_USEPOLLING=true
ENV WATCHPACK_POLLING=true Using Nextjs 13.4.12 and compilation seems a little bit slower! Also you can find step-by-step instruction in this article: https://faraasat.medium.com/using-next-js-13-app-directory-with-hot-reload-enabled-in-docker-simple-guide-60de42840d7e |
It worked for me too, but its very slow =( |
Thanks, this works for me too but very slow! Not instant as if I were to run the next app on its own outside of the Docker container! |
I ran into the same problem. It's not a next or docker problem but a docker host problem. In my case I was using colima, and the default filemount |
Running Next.js v14.0.4 inside a Docker container next.config.js
docker-compose.yml
I obtained the information from Solving Next.js fast refresh on Docker+Windows |
The webpack watcher option sucks. CPU inside the container goes to 110% from 10-20%, and RAM goes from a few MB to 3-4GB from 1-2GB. The fix for me was to add the |
compose.yaml - 仮想マシン内でのホットリロードに必要な環境変数を定義。 next.config.js - Strict Modeを有効化 - カスタムwebpackを作成し、ホットリロード機能を追加 参考: https://nao-uc.site/pg/next-js-docker-not-hot-reload/ https://nextjs.org/docs/app/api-reference/next-config-js/reactStrictMode https://nextjs.org/docs/app/api-reference/next-config-js/webpack https://webpack.js.org/configuration/watch/#watchoptions https://create-react-app.dev/docs/troubleshooting/#npm-start-doesnt-detect-changes vercel/next.js#36774
Is there an equivalent polling option for turbopack? The docs say that the webpack configuration is not supported, so fast refresh on docker+windows with turbopack will not work with the above solutions. |
In my case, I was using NGINX in a Docker Compose application. Just added in my
|
compose.yaml - 仮想マシン内でのホットリロードに必要な環境変数を定義。 next.config.js - Strict Modeを有効化 - カスタムwebpackを作成し、ホットリロード機能を追加 参考: https://nao-uc.site/pg/next-js-docker-not-hot-reload/ https://nextjs.org/docs/app/api-reference/next-config-js/reactStrictMode https://nextjs.org/docs/app/api-reference/next-config-js/webpack https://webpack.js.org/configuration/watch/#watchoptions https://create-react-app.dev/docs/troubleshooting/#npm-start-doesnt-detect-changes vercel/next.js#36774
compose.yaml - 仮想マシン内でのホットリロードに必要な環境変数を定義。 next.config.js - Strict Modeを有効化 - カスタムwebpackを作成し、ホットリロード機能を追加 参考: https://nao-uc.site/pg/next-js-docker-not-hot-reload/ https://nextjs.org/docs/app/api-reference/next-config-js/reactStrictMode https://nextjs.org/docs/app/api-reference/next-config-js/webpack https://webpack.js.org/configuration/watch/#watchoptions https://create-react-app.dev/docs/troubleshooting/#npm-start-doesnt-detect-changes vercel/next.js#36774
Unfortunatelly, tried every solution above and I wasn't able to fix it. |
@jhssilva If you are on windows try running project under WSL 2 as well as making all changes on WSL 2 instead of windows file system. |
Hey @nparoski . Thanks for your reply. |
now "docker compose up --build" spins up a development build locally, hot reloading on Windows 11 + Docker Desktop didn't work, but that may be Windows + WSL2 specific setup problem, see the following: - vercel/next.js#36774 - microsoft/WSL#4739 also: - remove deprecated version number from docker-compose.yml refs PT-1792
now "docker compose up --build" spins up a development build locally, hot reloading on Windows 11 + Docker Desktop didn't work, but that may be Windows + WSL2 specific setup problem, see the following: - vercel/next.js#36774 - microsoft/WSL#4739 also: - remove deprecated version number from docker-compose.yml refs PT-1792
Verify canary release
Provide environment information
Which example does this report relate to?
https://github.com/vercel/next.js/tree/canary/examples/with-docker
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
When I make changes in code app doesn't recompile itself. Hot reload doesn't work.
Expected Behavior
When I make changes in for example
pages/index.js
app should recompile and browsers should refresh page.To Reproduce
I make this repo to show the problem: https://github.com/GorlikItsMe/next-js-docker-swc-hot-reload-dont-work
Steps:
docker-compose up --build
/src/pages/index.js
My environment:
windows 10 with Docker Desktop.
The text was updated successfully, but these errors were encountered: