Docker绑定装载卷不会传播由角度“ng服务”执行

时间:2018-01-20 00:02:12

标签: angular docker angular-cli dockerfile mounted-volumes

遵循以下步骤:

  1. 定义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"]
    
  2. 从此Dockerfile构建映像:

    docker build -t my_angular_image .
    
  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 .
    
  4. 根据图片,运行装载应用程序卷的容器绑定:

    docker run -p 4200:4200 --mount type=bind,src=$PWD/app,dst=/volumes my_angular_image serve --host 0.0.0.0
    
  5. 结果: 第一个编译按预期工作,容器为应用程序提供服务。但是,当更改容器中必须由ng serve监视的文件的值(来自主机)时,不会触发新的角度构建(因此,服务的应用程序不会更新)。

    问题: 有人知道为什么在主机上更改绑定装载卷的值不会触发容器中的角度ng serve更新(就像不使用Docker时那样)?

    环境:

    • 操作系统:Ubuntu 16.04
    • Docker:18.01.0-ce

2 个答案:

答案 0 :(得分:2)

对于名为poll的angular-cli.json,有一个隐藏选项,指定您可以更改webpack监视文件更新的方式。 链接:

  1. https://webpack.js.org/configuration/watch/#watchoptions-poll
  2. https://github.com/angular/angular-cli/pull/1814
  3. https://github.com/angular/angular-cli/wiki/angular-cli#angular-cli-config-schema

答案 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

<强>现金:

  • @ PavelAgarkov的答案及其有用的链接。