Docker容器不会重新加载Angular应用 [英] Docker container doesn't reload Angular app
问题描述
我在由docker-compose
运行的docker容器中的ng serve
出现了一些问题.
I have some issue with ng serve
in my docker container running by docker-compose
.
Dockerfile
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连接对其进行了检查,并且容器中的文件已被编辑.再次重新启动容器后,将应用所有更改. 我以为,当我仅通过泊坞窗切换建筑物的图像来构成此图像时,它就会消失,但不会消失.
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
中的某些文件,重新加载所有文件,这样就可以在不重新启动容器的情况下正常工作.
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:
-
inotify->只需在
"scripts"
部分的以下行中编辑package.json
:"start": "ng serve --host 0.0.0.0 --poll"
,仅Windows主机需要
inotify -> just edit
package.json
in"scripts"
section this line:"start": "ng serve --host 0.0.0.0 --poll"
, required only for Windows host,
热重载->在Dockerfile
中添加expose 49153
并在docker-compose.yml
中添加端口- '49153:49153'
,就像提到的@kstromeiraos.
hot reload -> add expose 49153
in Dockerfile
and ports - '49153:49153'
in docker-compose.yml
like @kstromeiraos mentioned.
这篇关于Docker容器不会重新加载Angular应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!