遵循以下步骤:
定义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构建映像:
docker build -t my_angular_image .
使用图片创建新的角度应用:
// 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 .
根据图片,运行装载应用程序卷的容器绑定:
docker run -p 4200:4200 --mount type=bind,src=$PWD/app,dst=/volumes my_angular_image serve --host 0.0.0.0
结果:
第一个编译按预期工作,容器为应用程序提供服务。但是,当更改容器中必须由ng serve
监视的文件的值(来自主机)时,不会触发新的角度构建(因此,服务的应用程序不会更新)。
问题:
有人知道为什么在主机上更改绑定装载卷的值不会触发容器中的角度ng serve
更新(就像不使用Docker时那样)?
环境:
答案 0 :(得分:2)
对于名为poll
的angular-cli.json,有一个隐藏选项,指定您可以更改webpack监视文件更新的方式。
链接:
答案 1 :(得分:2)
为了使示例正常工作,请使用以下命令替换步骤3:
// 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
<强>现金:强>