为什么在为开发环境更改代码后,使用Docker容器的NextJS没有重新加载? [英] Why NextJS using Docker container did not reload after changed code for dev environment?

查看:37
本文介绍了为什么在为开发环境更改代码后,使用Docker容器的NextJS没有重新加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Dockerfile在Docker容器上运行NextJS并通过docker-compose运行,在JS文件(例如index.js)中更改了代码之后,Next服务器没有重新加载.

I'm trying to run the NextJS on a Docker container using Dockerfile and running via docker-compose, after I changed my code in a JS file (such as index.js) the Next server did not reload.

但是,当我尝试在不使用Docker的情况下在室外运行时(通过直接执行"npm run dev"命令),下一台服务器确实重新加载成功.

But when I've tried to run outside without using Docker (by executing the "npm run dev" command directly) the Next server did reload smoothly.

我还尝试通过"nodemon"命令(在容器内)运行服务器,但也没有成功.

I've also tried to run the server by "nodemon" command (inside a container), it did not make it either.

Dockerfile:

Dockerfile:

FROM node:10.14.2-alpine
COPY . /home/next_app
WORKDIR /home/next_app
RUN npm install

docker-compose.yml:

docker-compose.yml:

version: "3.6"
services:
  self_nextjs:
    container_name: self_nextjs
    build:
        context: ./app
        dockerfile: Dockerfile
    ports:
        - 3000:3000
    volumes:
        - ./app:/home/next_app
        - /home/next_app/node_modules
    networks:
        - zen_frontend
    restart: always
    command: npm run dev

networks:
  zen_frontend:
      name: zen_frontend
      driver: bridge

任何建议将不胜感激.

推荐答案

您是否通过公开webpack的默认热重装端口进行了测试?

Have you tested by exposing webpack default hot reload port?

添加到您的 Dockerfile

...
EXPOSE 49153
...

并更新您的 docker-compose.yml

version: "3.6"
services:
  self_nextjs:
    container_name: self_nextjs
    build:
        context: ./app
        dockerfile: Dockerfile
    ports:
        - 3000:3000
        - 49153:49153
    volumes:
        - ./app:/home/next_app
        - /home/next_app/node_modules
    networks:
        - zen_frontend
    restart: always
    command: npm run dev

networks:
  zen_frontend:
      name: zen_frontend
      driver: bridge

希望获得帮助,

致谢

这篇关于为什么在为开发环境更改代码后,使用Docker容器的NextJS没有重新加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆