为什么使用 Docker 容器的 NextJS 在更改开发环境的代码后没有重新加载? [英] Why NextJS using Docker container did not reload after changed code for dev environment?
问题描述
我正在尝试使用 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"命令),Next 服务器确实重新加载顺利.
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屋!