首页 > 解决方案 > 如何使生产就绪 Angular Dotnet Core Docker 应用程序

问题描述

我们正在尝试制作一个具有 .Net App Server 和 Angular 客户端的 Docker 容器

项目的结构是 ReportBackEnd/ -some default .net core dirs/ - angular/

我们创建了以下 Docker 文件

FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
# Setup NodeJs
RUN apt-get update -qq && \
    apt-get install -qq -y wget && \
    apt-get install -qq -y gnupg2 && \
    wget -qO- https://deb.nodesource.com/setup_8.x | bash - && \
    apt-get install -qq -y build-essential nodejs && \
    apt-get install -qq -y nginx
# End setup

WORKDIR /app
EXPOSE 80

FROM microsoft/dotnet:2.1-sdk AS build
# Setup NodeJs
RUN apt-get update -qq && \
    apt-get install -qq -y wget && \
    apt-get install -qq -y gnupg2 && \
    wget -qO- https://deb.nodesource.com/setup_8.x | bash - && \
    apt-get install -qq -y build-essential nodejs && \
    apt-get install -qq -y nginx
# End setup
WORKDIR /src
COPY ["ReportBackEnd.csproj", "ReportBackEnd/"]
RUN dotnet restore "ReportBackEnd/ReportBackEnd.csproj"

COPY ["angular/package.json", "ReportBackEnd/angular/"]

RUN cd ReportBackEnd/angular \
    && npm i --silent

COPY . ./
WORKDIR /src/ReportBackEnd
RUN dotnet build "ReportBackEnd.csproj" -c Release -o /app

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

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

从 Visual Studio 的 Docker 按钮运行此文件按预期工作。

但是,当我们尝试自己构建并运行它时,我们会得到:

程序不包含适用于入口点的静态“Main”方法

我们使用的命令是:

docker build -f "C:\<dirs>\ReportBackEnd\Dockerfile" -t core:dev --target base
docker run -dt -p 80:80 core:dev

标签: .netangulardocker

解决方案


推荐阅读