Angular Docker热重装在Windows上不起作用 [英] Angular Docker hot reload not working on windows
问题描述
在Windows的Docker容器中运行新创建的角度应用程序不会在更改时热重新加载该应用程序. 我尝试了 Docker容器不会重新加载Angular应用.
Running a freshly created angular app in a docker container in windows does not hot reload the app on changes. I tried this Docker container doesn't reload Angular app.
但仍然失败,如果我创建映像,然后运行得到的容器:
but keeps failing, if I create the image then run the container I get:
web_1 | npm ERR! enoent ENOENT: no such file or directory, open '/usr/src/app/package.json'
我还尝试了以下文章(适用于Mac,但不适用于Windows):
对Angular应用进行Docker化
I also tried following this article (Works on Mac but not Windows):
Dockerizing an Angular App
我尝试将--poll
添加到我的angular.json
:
"docker": {
"poll": 2000
},
- 这是我的DockerFile
FROM node:8.11.2
# set working directory
RUN mkdir /usr/src/app
WORKDIR /usr/src/app
# add `/usr/src/app/node_modules/.bin` to $PATH
ENV PATH /usr/src/app/node_modules/.bin:$PATH
COPY package.json /usr/src/app/package.json
RUN npm install
RUN npm install -g @angular/cli@6.1.5
# add app
COPY . /usr/src/app
EXPOSE 4200 49153
# start app
CMD ng serve --port 4200 --host 0.0.0.0 --poll 1
这就是我的运行方式:
docker build -t something-clever .
That's how I run it:
docker build -t something-clever .
对于容器:
docker run -it -v C:/Users/test-docker -v /usr/src/app/node_module -p 4200:4200 -p 49153:49153 --rm something-clever bash -c "npm start"
For the container:
docker run -it -v C:/Users/test-docker -v /usr/src/app/node_module -p 4200:4200 -p 49153:49153 --rm something-clever bash -c "npm start"
感谢您的帮助. 谢谢你.
Any help is appreciated. Thank you.
推荐答案
在您的配置中出现了一些问题,首先我假设您要将C:/Users/test-docker
绑定到/usr/src/app/node_module
?
There are a few things going wrong in your configuration, first of all I assume you want to bind C:/Users/test-docker
to /usr/src/app/node_module
?
如果不是这种情况,则需要将本地项目目录绑定到/usr/src/app/node_module
.您可以使用
If this is not the case you will need to bind the local project directory to /usr/src/app/node_module
. You can do this by using the syntax -v <source_dir>:<target_dir>
as described in the docs.
所以这将导致docker run -it -v C:/Users/test-docker:/usr/src/app/node_module -p 4200:4200 -p 49153:49153 --rm something-clever bash -c "npm start"
第二,当前您正在构建图像时复制文件,而不是运行图像时复制文件.这意味着,除非重新启动,否则docker映像中当前存在的文件将始终保持不变.当您直接将项目目录绑定到容器中时,此步骤将变得过时.
Second of all, you are currently copying the files when you build the image, not when you run it. Meaning that the files currently present in the docker image will always remain the same unless you restart it. This step will become obsolete when you bind your project directory directly into the container.
这样做,文件将同时在docker容器内的主机和上更新.因此,您可以在固定卷安装后从docker文件中删除复制行.
By doing this the files will be updated on both your host and inside the docker container. So you can just remove the copy lines from your docker file after you have fixed the volume mounts.
希望对您有帮助
这篇关于Angular Docker热重装在Windows上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!