适用于Windows,AspNetCore和aspnet-webpack热门模块的Docker

时间:2018-12-05 19:43:16

标签: asp.net-core npm webpack docker-windows hot-module-replacement

我最近将我的AspNetCore Web应用程序转换为使用docker容器进行本地开发,并且在使npm模块“ aspnet-webpack”正常工作时遇到麻烦。

启动容器时,出现以下错误:

Microsoft.AspNetCore.NodeServices.HostingModels.NodeInvocationException: Webpack dev middleware failed because of an error while loading 'aspnet-webpack'. Error was: Error: ENOENT: no such file or directory, lstat 'C:\ContainerMappedDirectories'

当然,如果我注释掉下面的代码片段,该错误就会消失,但是如果有人对使我的webpack热模块起作用的建议,我将不胜感激:

app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
{
    HotModuleReplacement = true
});

这是我的DockerFile的简化代码段(希望我什么都没丢失):

FROM microsoft/dotnet:2.1-aspnetcore-runtime-nanoserver-sac2016 AS base
# Pretend I install nodejs here or the image above already has it
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM microsoft/dotnet:2.1-sdk-nanoserver-1803 AS build
WORKDIR /src
COPY ["WebApp/WebApp.csproj", "WebApp/"]
RUN dotnet restore "WebApp/WebApp.csproj"
COPY . .
WORKDIR "/src/WebApp"
RUN dotnet build "WebApp.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "WebApp.csproj" -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "WebApp.dll"]

还有我的docker-compose.yml的简化代码段:

services:
  webapp:
    image: ${DOCKER_REGISTRY-}webapp
    build:
      context: .
      dockerfile: WebApp\Dockerfile
  environment:
    - ASPNETCORE_ENVIRONMENT=Development
    - ASPNETCORE_URLS=http://+:80
  ports:
    - "53760:80"
  volumes:
    - ${APPDATA}/ASP.NET/Https:C:\Users\ContainerUser\AppData\Roaming\ASP.NET\Https:ro
    - ${APPDATA}/Microsoft/UserSecrets:C:\Users\ContainerUser\AppData\Roaming\Microsoft\UserSecrets:ro
    - .\WebApp\node_modules:C:/app/node_modules

请注意,我尝试将我的node_modules从本地计算机映射到容器,以查看这是否有助于热模块查找“ aspnet-webpack”。

0 个答案:

没有答案