【发布时间】:2018-06-29 07:00:55
【问题描述】:
按照以下步骤操作:
-
定义 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 . -
使用图像创建一个新的 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 监视的文件的值(来自主机)时,不会触发新的角度构建(因此,服务的应用程序不会更新)。
问题:
有人知道为什么更改主机上绑定挂载卷的值不会触发容器中的 ng serve 角度更新(就像不使用 Docker 时那样)?
环境:
- 操作系统:Ubuntu 16.04
- Docker : 18.01.0-ce
【问题讨论】:
-
你在哪个操作系统上运行 docker?
-
是的,这不适用于带有 Linux 容器的 Windows docker 主机。
-
@TarunLalwani 我添加了一个环境部分,我在 Ubuntu Xenial 上。
-
@Brian 即使我不在 Windows docker 主机上,我也很好奇,你能解释一下为什么这在带有 Linux 容器的 Windows docker 主机上不起作用吗?
标签: angular docker angular-cli dockerfile mounted-volumes