首页 > 解决方案 > .NET Core 3 Web API + SPA 应用程序 (vue) 的 Dockerfile

问题描述

由于 .NET Core 3 Web API 可以通过 NuGet 包 VueCliMiddleware 与 Vue 很好地配合使用。如何编写一个有效的简单 Dockerfile?

标签: vue.jsasp.net-web-apidockerfileasp.net-core-3.0asp.net-core-3.1

解决方案


嗯,首先我不推荐这个,因为构建时间很慢。您在下面看到的这个 dockerfile 是实验性的,所以请确保您进行必要的修改以使其准备好投入生产!

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app

# Copy csproj and restore as distinct layers
COPY . .
RUN dotnet restore Nozomi.Web2/Nozomi.Web2.csproj

# Required libraries in Unix
RUN apt-get update -q && apt-get install -q -y \
        curl apt-transport-https apt-utils dialog \
        make g++ build-essential

# Node Bash Script for Debian
# https://github.com/nodesource/distributions#deb
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -

# Propagate Node for Docker
RUN apt-get update \
    && apt-get install -y nodejs

# Copy everything else and build
RUN dotnet publish Nozomi.Web2/Nozomi.Web2.csproj -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "Nozomi.Web2.dll"]

推荐阅读