Next.js Discord

Discord Forum

running Next.js inside a docker container

Unanswered
Albacore posted this in #help-forum
Open in Discord
AlbacoreOP
Im trying to develop with Next.js inside a docker container on windows system. I noticed a probleme where changes where not detected when i saved a file.
I found a solution where people set the poll option for webpack inside the next.config. I didnt like the approach and found another solution where the volume type is set to bind inside the docker-composer.yml. Now when i saved a file the changes where detected and page was reloaded.
I still have a problem that if i create a new route with a page.tsx the new route isnt registered until i restart the container. If i add a new component file i can include that inside a page without restarting the container. Did anyone have the same problem and found a solution?

structure
docker-compose.yml
dockerfile
├── docker-next

dockerfile
FROM node:18-alpine

WORKDIR /app

COPY ./docker-next/package.json ./

RUN npm install

COPY . .

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


docker-compose.yml
version: '3.5'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: docker-next
    ports:
      - 3000:3000
      - 49153:49153
    volumes:
      - type: bind
        source: ./docker-next
        target: /app
      - /app/node_modules
    # approach with poll
    # environment:  
    # - NEXT_WEBPACK_USEPOLLING=0

6 Replies

@Ray https://syntackle.com/blog/containerizing-a-nextjs-application-using-docker-st_G0u/#live-reloading-hmr
AlbacoreOP
That is the same solution as i tried. It fixed the hot reloading Problem. But still new created routs would show error 404 until i restart my docker. :/
Asiatic Lion
ig impossible, :box_cat_hide:
kindly let me know if you found the solution 🙏
AlbacoreOP
@Asiatic Lion do you have same problem? Kinda weird nobody else mentions this below all the posts with the hot reloading problem.
Asiatic Lion
tbh, I haven't thought about it at all.