Docker 绑定挂载卷不传播由 angular `ng serve` 执行监视的更改事件 [英] Docker bind mount volumes do not propagate changes events watched by angular `ng serve` execution

查看:22
本文介绍了Docker 绑定挂载卷不传播由 angular `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 .
    

  • 使用图像创建新的 Angular 应用程序:

  • 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 绑定挂载卷不传播由 angular `ng serve` 执行监视的更改事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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