I'm trying to build a Docker Image from my Angular2 App that runs on ASP.Net Core. 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:
Uncaught ReferenceError: vendor_ is not defined
Therefor I assumed that the problem lies within webpack and added the following code:
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:
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?
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 ...
. The new Dockerfile looks like this:
FROM microsoft/dotnet:aspnetcore-runtime
WORKDIR /app
COPY out .
EXPOSE 7000/tcp
ENTRYPOINT ["dotnet", "myApp.dll"]
Hope it helps!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.