Docker MERN 部署 - 热重载不工作
Docker MERN Deployment - hot reload is not working
我正在将我的存储库移动到具有单一服务的 docker 容器,并且一切似乎都按预期工作,除了反应开发环境的热重新加载。也许有必要为客户开发服务使用卷?代码:
Dockerfile(反应):
FROM node:14
WORKDIR /client
ENV PATH /client/node_modules/.bin:$PATH
COPY package*.json .
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
docker-compose.yaml
version: "3"
services:
server:
build:
context: ./server
ports:
- "5000:5000"
networks:
- default
depends_on:
- db
client-development:
build:
context: ./client
stdin_open: true
ports:
- "3000:3000"
environment:
- NODE_ENV=development
- CHOKIDAR_USEPOLLING=true
networks:
- default
depends_on:
- server
db:
image: "mongo"
ports:
- "27017:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: test
networks:
- default
volumes:
- mongo-data:/data/db
networks:
default:
driver: bridge
volumes:
mongo-data:
driver: local
您需要创建一个绑定挂载,以便在主机和 运行 您的 React 应用程序的容器之间进行镜像,例如
Docker 文件
FROM node:14
WORKDIR /react-starter-kit
COPY . .
RUN npm i
CMD [ "npm", "start" ]
docker-compose.yaml
version: '3.8'
services:
starter:
build: .
image: react-starter-kit
restart: always
ports:
- 3000:3000
volumes:
- ./node_modules:/react-starter-kit/node_modules
- ./src:/react-starter-kit/src
我正在将我的存储库移动到具有单一服务的 docker 容器,并且一切似乎都按预期工作,除了反应开发环境的热重新加载。也许有必要为客户开发服务使用卷?代码:
Dockerfile(反应):
FROM node:14
WORKDIR /client
ENV PATH /client/node_modules/.bin:$PATH
COPY package*.json .
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
docker-compose.yaml
version: "3"
services:
server:
build:
context: ./server
ports:
- "5000:5000"
networks:
- default
depends_on:
- db
client-development:
build:
context: ./client
stdin_open: true
ports:
- "3000:3000"
environment:
- NODE_ENV=development
- CHOKIDAR_USEPOLLING=true
networks:
- default
depends_on:
- server
db:
image: "mongo"
ports:
- "27017:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: test
networks:
- default
volumes:
- mongo-data:/data/db
networks:
default:
driver: bridge
volumes:
mongo-data:
driver: local
您需要创建一个绑定挂载,以便在主机和 运行 您的 React 应用程序的容器之间进行镜像,例如
Docker 文件
FROM node:14
WORKDIR /react-starter-kit
COPY . .
RUN npm i
CMD [ "npm", "start" ]
docker-compose.yaml
version: '3.8'
services:
starter:
build: .
image: react-starter-kit
restart: always
ports:
- 3000:3000
volumes:
- ./node_modules:/react-starter-kit/node_modules
- ./src:/react-starter-kit/src