简体   繁体   English

Docker + Angular2 + ASP.NET Core构建错误

[英]Docker + Angular2 + ASP.NET Core build errors

I'm trying to build a Docker Image from my Angular2 App that runs on ASP.Net Core. 我正在尝试从在ASP.Net Core上运行的Angular2应用程序构建Docker映像。 I've used the Dockerfile from https://github.com/MarkPieszak/aspnetcore-angular2-universal/blob/master/Dockerfile to create my Dockerfile and it almost works except for folloing error showing up when I run the image I created: 我使用了https://github.com/MarkPieszak/aspnetcore-angular2-universal/blob/master/Dockerfile中的Dockerfile创建我的Dockerfile,除了运行我创建的图像时出现以下错误之外,它几乎可以正常工作:

Uncaught ReferenceError: vendor_ is not defined

Therefor I assumed that the problem lies within webpack and added the following code: 因此,我认为问题出在webpack内,并添加了以下代码:

RUN webpack --config webpack.config.vendor.js

But now I'm getting this error: 但是现在我得到了这个错误:

/bin/sh: 1: webpack: not found

After that I tried: 之后,我尝试:

RUN npm install webpack -g
RUN npm install webpack-cli -g

But that keeps failing with cryptic errors like: 但是,这样的错误总是会失败,例如:

Error: Cannot find module 'js.clone'

That's the Dockerfile I copied for my Dockerfile and to what I added the aformentioned lines of Code: 这就是我为Dockerfile复制的Dockerfile,并添加到上述代码行中:

FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
RUN apt-get -qq update && apt-get install -y build-essential
RUN curl -sL https://deb.nodesource.com/setup_10.x |  bash -
RUN apt-get install -y nodejs
RUN npm i -g --unsafe-perm node-sass && npm rebuild --unsafe-perm node-sass -f
EXPOSE 80

FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY Asp2017.csproj .
RUN apt-get -qq update && apt-get install build-essential -y && apt-get install -my wget gnupg && apt-get -qq -y install bzip2 
RUN curl -sL https://deb.nodesource.com/setup_10.x |  bash -
RUN apt-get install -y nodejs
RUN dotnet restore ./Asp2017.csproj
COPY . .
WORKDIR /src/
RUN dotnet build Asp2017.csproj -c Release -o /app

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

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

So my question is: What is best practice for a Dockerfile for Angular2 + ASP.NET Core? 所以我的问题是:Angular2 + ASP.NET Core的Dockerfile的最佳实践是什么?

Thanks for any ideas and help! 感谢您的任何想法和帮助!

For anyone else facing similar problems: I actually only managed to get this to work by running webpack and dotnet publish -c Release -o out before docker build ... . 对于其他面临类似问题的人:我实际上只能通过在webpack docker build ...之前运行webpackdotnet publish -c Release -o out webpack正常工作。 The new Dockerfile looks like this: 新的Dockerfile如下所示:

    FROM microsoft/dotnet:aspnetcore-runtime
    WORKDIR /app
    COPY out .
    EXPOSE 7000/tcp
    ENTRYPOINT ["dotnet", "myApp.dll"]

Hope it helps! 希望能帮助到你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM