Docker绑定安装卷不会传播角度的ng serve执行所监视的更改事件 [英] Docker bind mount volumes do not propagate changes events watched by angular `ng serve` execution

查看:131
本文介绍了Docker绑定安装卷不会传播角度的ng serve执行所监视的更改事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行以下步骤:

  1. 定义Dockerfile:

  1. 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屋!

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