Docker绑定安装卷不会传播角度的ng serve执行所监视的更改事件 [英] Docker bind mount volumes do not propagate changes events watched by angular `ng serve` execution
问题描述
执行以下步骤:
-
定义Dockerfile:
Define the Dockerfile:
FROM node:alpine
RUN yarn global add @angular/cli
RUN yarn global add node-sass
RUN mkdir /volumes
WORKDIR /volumes
EXPOSE 4200
ENTRYPOINT ["ng"]
从此Dockerfile构建映像:
Build an image from this Dockerfile:
docker build -t my_angular_image .
使用图像创建一个新的角度应用程序:
Use the image to create a new angular app :
// Create the new app
docker run --rm --mount type=bind,src=$PWD,dst=/volumes my_angular_image new my-app --directory app --style scss
// Change ownership of the generated app
sudo chown -R $USER:$USER .
基于图像,运行容器绑定以装入应用程序卷:
Based on the image, run a container bind mounting the app volume:
docker run -p 4200:4200 --mount type=bind,src=$PWD/app,dst=/volumes my_angular_image serve --host 0.0.0.0
结果:
第一次编译将按预期方式进行,并且容器将为该应用程序提供服务.但是,当更改容器中ng serve
必须监视的文件的值(来自主机)时,不会触发新的角度构建(因此,不会更新所提供的应用程序).
Results:
The first compilation works as expected and the container serves the app. However, when changing the value (from host) of a file which has to be watched by ng serve
in container, a new angular build is not triggered (and so, the served app is not updated).
问题:
有人知道为什么更改主机上的绑定安装卷的值不会触发容器中的角度ng serve
更新(就像不使用Docker时一样)吗?
Question:
Does someone know why changing the value of a bind mount volume on host does not trigger the angular ng serve
update in container (as it does when not using Docker)?
环境:
- 操作系统:Ubuntu 16.04
- Docker:18.01.0-ce
推荐答案
为使该示例正常工作,请用以下命令替换步骤3:
In order to make the example working, replace step 3 by the commands below:
// Create the new app
docker run --rm --mount type=bind,src=$PWD,dst=/volumes my_angular_image new my-app --directory app --style scss
// Change ownership of the generated app
sudo chown -R $USER:$USER .
// Configure angular-cli polling:
sed -i 's/\"styleExt\": \"scss\",/"styleExt": "scss", "poll": 1000,/g' $PWD/app/.angular-cli.json
积分:
- @PavelAgarkov的答案及其有用的链接.
这篇关于Docker绑定安装卷不会传播角度的ng serve执行所监视的更改事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!