Docker 绑定安装卷不会传播由 angular `ng serve` 执行监视的更改事件
Docker bind mount volumes do not propagate changes events watched by angular `ng serve` execution
执行以下步骤:
定义Docker文件:
FROM node:alpine
RUN yarn global add @angular/cli
RUN yarn global add node-sass
RUN mkdir /volumes
WORKDIR /volumes
EXPOSE 4200
ENTRYPOINT ["ng"]
从这个 Docker 文件构建图像:
docker build -t my_angular_image .
使用图像创建新的 angular 应用程序:
// 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
监视的文件的值(来自主机)时,不会触发新的 angular 构建(因此,服务的应用程序不会更新)。
问题:
有人知道为什么更改主机上绑定安装卷的值不会触发容器中的 angular ng serve
更新(就像不使用 Docker 时一样)吗?
环境:
- OS : Ubuntu 16.04
- Docker : 18.01.0-ce
angular-cli.json 有一个名为 poll
的隐藏选项,通过指定您可以更改下划线 webpack 监视文件更新的方式。
链接:
为了使示例正常运行,请将步骤 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
学分:
- @PavelAgarkov 的回答及其有用的链接。
执行以下步骤:
定义Docker文件:
FROM node:alpine RUN yarn global add @angular/cli RUN yarn global add node-sass RUN mkdir /volumes WORKDIR /volumes EXPOSE 4200 ENTRYPOINT ["ng"]
从这个 Docker 文件构建图像:
docker build -t my_angular_image .
使用图像创建新的 angular 应用程序:
// 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
监视的文件的值(来自主机)时,不会触发新的 angular 构建(因此,服务的应用程序不会更新)。
问题:
有人知道为什么更改主机上绑定安装卷的值不会触发容器中的 angular ng serve
更新(就像不使用 Docker 时一样)吗?
环境:
- OS : Ubuntu 16.04
- Docker : 18.01.0-ce
angular-cli.json 有一个名为 poll
的隐藏选项,通过指定您可以更改下划线 webpack 监视文件更新的方式。
链接:
为了使示例正常运行,请将步骤 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
学分:
- @PavelAgarkov 的回答及其有用的链接。