[英]ASP.NET Core Angular Template in Docker watching file changes
I've created the ASP.NET Core Angular project with dotnet new angular
and hosted in the docker.我已经使用
dotnet new angular
创建了 ASP.NET 核心 Angular 项目,并托管在 Z05B6053C41A2130AFB686 中。
How to look for file changes without having to reboot the docker containers again?如何在无需重新启动 docker 容器的情况下查找文件更改?
Dockerfile Dockerfile
FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
WORKDIR /app
COPY "3_UI/MyAccounts.Web/MyAccounts.Web.csproj" ./myapp/
RUN dotnet restore "./myapp/MyAccounts.Web.csproj"
COPY "3_UI/MyAccounts.Web/." ./myapp/
WORKDIR /app/myapp
# Install Node, NPM and VS Debugger
RUN apt-get update && apt-get install -y curl sudo unzip procps
RUN apt-get install -y --no-install-recommends apt-utils
RUN curl -sSL https://aka.ms/getvsdbgsh | bash /dev/stdin -v latest -l /publish/vsdbg;
RUN sudo apt-get install -y nodejs
RUN curl -L https://npmjs.org/install.sh | sudo sh
RUN echo "NODE Version:" && node --version
RUN echo "NPM Version:" && npm --version
RUN dotnet publish -c Debug -o out
FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim AS runtime
WORKDIR /app
EXPOSE 9000
# Install Node, NPM and VS Debugger
RUN apt-get update && apt-get install -y curl sudo unzip procps
RUN apt-get install -y --no-install-recommends apt-utils
RUN curl -sSL https://aka.ms/getvsdbgsh | bash /dev/stdin -v latest -l /publish/vsdbg;
RUN sudo apt-get install -y nodejs
RUN curl -L https://npmjs.org/install.sh | sudo sh
RUN echo "NODE Version:" && node --version
RUN echo "NPM Version:" && npm --version
# ENV ASPNETCORE_ENVIRONMENT=development
ENV ASPNETCORE_URLS=http://+:9000
COPY --from=build /app/myapp/out .
ENTRYPOINT [ "dotnet", "MyAccounts.Web.dll"]
Thought adding ENV ASPNETCORE_ENVIRONMENT=development
will watch for client app file changes but it is throwing the below error after the container is up.考虑添加
ENV ASPNETCORE_ENVIRONMENT=development
将监视客户端应用程序文件的更改,但在容器启动后它会引发以下错误。
app_web_service | npmfail: Microsoft.AspNetCore.SpaServices[0]
app_web_service | npm ERR! code ENOENT
app_web_service |
app_web_service | fail: Microsoft.AspNetCore.SpaServices[0]
app_web_service | npm ERR! syscall open
app_web_service |
app_web_service | fail: Microsoft.AspNetCore.SpaServices[0]
app_web_service | npm ERR! path /app/ClientApp/package.json
app_web_service |
app_web_service | fail: Microsoft.AspNetCore.SpaServices[0]
app_web_service | npm ERR! errno -2
app_web_service |
app_web_service | fail: Microsoft.AspNetCore.SpaServices[0]
app_web_service | npm ERR! enoent ENOENT: no such file or directory, open '/app/ClientApp/package.json'
app_web_service |
app_web_service | fail: Microsoft.AspNetCore.SpaServices[0]
app_web_service | npm ERR! enoent This is related to npm not being able to find a file.
app_web_service |
app_web_service | fail: Microsoft.AspNetCore.SpaServices[0]
app_web_service | npm ERR! enoent
app_web_service |
app_web_service | npm ERR!fail: Microsoft.AspNetCore.SpaServices[0]
app_web_service | npm ERR! A complete log of this run can be found in:
app_web_service |
app_web_service | fail: Microsoft.AspNetCore.SpaServices[0]
app_web_service | npm ERR! /root/.npm/_logs/2021-05-08T11_54_23_879Z-debug.log
Any other configurations missing to watch for file changes?是否缺少任何其他配置来监视文件更改?
I am having this working but still not the optimised way.我有这个工作,但仍然不是优化的方式。 I have split .NET Core and Angular in its own container.
我在自己的容器中拆分了 .NET Core 和 Angular 。
Angular ClientApp Angular ClientApp
# base image
FROM node:alpine
# set working directory
WORKDIR /app
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH
# install and cache app dependencies
COPY package*.json /app/
RUN npm install
RUN npm install -g @angular/cli@11.2.12
# add app
COPY . /app
# start app
CMD ng serve --host 0.0.0.0 --poll 500
.NET Core App .NET 核心应用
FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim as build
ENV DOTNET_USE_POLLING_FILE_WATCHER 1
WORKDIR /app
COPY . .
RUN dotnet restore
RUN apt-get update && apt-get install -y curl sudo unzip procps
RUN apt-get install -y --no-install-recommends apt-utils
RUN curl -sSL https://aka.ms/getvsdbgsh | bash /dev/stdin -v latest -l /publish/vsdbg;
ENTRYPOINT [ "dotnet", "watch", "run", "--urls", "http://+:9000"]
Docker Compose Docker 组成
myaccounts.web:
container_name: app_web
build:
context: ./3_UI/MyAccounts.Web/ClientApp/
dockerfile: Dockerfile
volumes:
- ./3_UI/MyAccounts.Web/ClientApp/:/app
- '/app/node_modules'
ports:
- 4200:4200
depends_on:
- db
myaccounts.web.service:
container_name: api_gateway
build:
context: ./3_UI/MyAccounts.Web/
dockerfile: Dockerfile
volumes:
- ./3_UI/MyAccounts.Web/:/app
environment:
- ASPNETCORE_URLS=http://localhost:9000
- ASPNETCORE_ENVIRONMENT=development
ports:
- 9000:9000
depends_on:
- db
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.