Next.js Discord

Discord Forum

Nextjs hot reload not working in docker container

Unanswered
Chinese Alligator posted this in #help-forum
Open in Discord
Chinese AlligatorOP
Hi, so when I tried running my docker container for Nextjs, it's not detecting the changes. The files in the docker container is synced btw.

I'm on windows11 currently.

This is part of my docker-compose for Nextjs:
    client:
        build: ./client
        ports:
            - "3000:3000"
        environment:
            NEXT_PUBLIC_API_URL: http://localhost:5000
            CHOKIDAR_USEPOLLING: true
        volumes:
            - ./client:/app
            - client_node_modules:/app/node_modules
            - /app/.next


Dockerfile:
FROM node:20

WORKDIR /app

COPY package*.json ./
RUN npm install

COPY . .

EXPOSE 3000

CMD ["npm", "run", "dev"]

10 Replies

Northeast Congo Lion
👍
@Northeast Congo Lion 👍
Chinese AlligatorOP
?
Chinese AlligatorOP
I still can't figure out a solution to this
Rufous-capped Warbler
@Chinese Alligator did a quick Google search, I think you could try using the WATCHPACK_POLLING environment variable and setting it to "true"
@Rufous-capped Warbler <@788150000215261204> did a quick Google search, I think you could try using the `WATCHPACK_POLLING` environment variable and setting it to "true"
Chinese AlligatorOP
Sorry, I should have mentioned it sooner, but I tried that and CHOKIDAR_USEPOLLING: true
I had the same problem in my backend, but setting CHOKIDAR_USEPOLLING: true worked for me. However, for my nextjs app, nothing worked so far...
@Chinese Alligator I had the same problem in my backend, but setting `CHOKIDAR_USEPOLLING: true` worked for me. However, for my nextjs app, nothing worked so far...
Rufous-capped Warbler
Another thing you could try that I've stumbled upon while searching was the use of the following code, in next.config.js:
const nextConfig = {
  webpack: (config => {
    config.watchOptions = {
      poll: 1000,
      aggregateTimeout: 300,
      ignored: ['**/node_modules']
    }
    return config
  })
}
Chinese AlligatorOP
@Rufous-capped Warbler It doesn't work 😔
The only thing I can do for now is run my frontend normally as is without a container