Docker 容器不会重新加载 Angular 应用程序 [英] Docker container doesn't reload Angular app

查看:27
本文介绍了Docker 容器不会重新加载 Angular 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在由 docker-compose 运行的 docker 容器中的 ng serve 有一些问题.

I have some issue with ng serve in my docker container running by docker-compose.

Dockerfile

FROM node:7.1

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json /usr/src/app
RUN npm install
RUN npm install -g angular-cli
COPY . /usr/src/app

EXPOSE 4200

CMD [ "npm", "start" ]'

还有我的 docker-compose.yml

And my docker-compose.yml

web:
    build: .
    ports:
        - '8089:4200'
    volumes:
        - .:/usr/src/app/
    environment:
        - NODE_ENV=dev
    command: bash -c "npm start"

当我运行它时一切正常,但编辑文件不会重新加载应用程序.文件已更改,我确定是因为我通过 ssh 连接检查它并编辑了容器中的文件.当容器再次重新启动时,每个更改都会被应用.我以为当我只通过 docker 切换构建图像来组合时,它会消失,但不会.

Everything works great when I run it but the editing file does not rise reload of application. File is changed, I'm sure because I check it by ssh connection and the file in the container is edited. When container is restarted again every change is applied. I thought when I switch with building image by only docker to compose this will disappearr, but do not.

当我从 docker exec webpack 调用 touch 某个文件时,重新加载所有文件,它无需重新启动容器即可工作.

When I call touch some file from docker exec webpack reload all file and it work without restarting container.

有人有解决方案吗?

推荐答案

我找到了两个问题的解决方案:

I found solution for both problems:

  1. inotify -> 只需编辑 "scripts" 部分中的 package.json 这一行:"start": "ng serve --host 0.0.0.0 --poll",仅Windows主机需要,

  1. inotify -> just edit package.json in "scripts" section this line: "start": "ng serve --host 0.0.0.0 --poll", required only for Windows host,

hot reload -> 在 Dockerfile 中添加 expose 49153 并在 docker- 中添加端口 - '49153:49153'compose.yml 就像提到的@kstromeiraos.

hot reload -> add expose 49153 in Dockerfile and ports - '49153:49153' in docker-compose.yml like @kstromeiraos mentioned.

这篇关于Docker 容器不会重新加载 Angular 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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