【问题标题】:Docker-compose uses wrong ASP.NET Core version (3.0 instead of 3.1)Docker-compose 使用错误的 ASP.NET Core 版本(3.0 而不是 3.1)
【发布时间】:2020-06-15 02:59:18
【问题描述】:

正如标题所示,docker-compose 尝试构建 3.0 的 ASP.NET Core 映像而不是 3.1。

我最近使用这篇 Microsoft 文章中的说明从 3.0 更新了我的项目:https://docs.microsoft.com/en-us/aspnet/core/migration/30-to-31?view=aspnetcore-3.1&tabs=visual-studio 除了 global.json 部分,因为我不使用它。

这是我尝试过的:

这是我的 yaml 文件:

version: "3.7"
services:
    hraapi: 
        build: .
        environment:
            - ASPNETCORE_ENVIRONMENT=Development
        image: vmandeal/hra.api:testing
        container_name: hra.api
        ports:
            - "5000:80"
        depends_on:
            - hradb
    hradb:
        image: "mcr.microsoft.com/mssql/server:2019-latest"
        container_name: hra.api.db
        ports:
            - "1433:1433"
        environment:
            SA_PASSWORD: "YeyPass"
            ACCEPT_EULA: "Y"

这是我的项目文件:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
    <PackageReference Include="FluentValidation.AspNetCore" Version="8.5.1" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="3.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Analyzers" Version="3.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.1" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.1" />
    <PackageReference Include="Steeltoe.Discovery.ClientCore" Version="2.4.0" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc4" />
  </ItemGroup>

</Project>

【问题讨论】:

  • 你的项目中应该有一个Dockerfile。我猜是使用了错误的基础图片标签。
  • 你更新你的Dockerfile 来使用asp.net core 3.1的图片了吗?
  • 是的,“来自 mcr.microsoft.com/dotnet/core/aspnet:3.0 WORKDIR /app COPY bin/Debug/netcoreapp3.0/publish 。”如此愚蠢。我完全忽略了它。谢谢 ChristophLütjen 和 Exploding Kitten。

标签: docker asp.net-core docker-compose


【解决方案1】:

你应该重新创建你的 docker 文件,

在你的 docker 文件中有一个 FROM 关键字,它显示你的容器应该从哪个图像开始。

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["MainApplication/MainApplication.csproj", "MainApplication/"]
RUN dotnet restore "MainApplication/MainApplication.csproj"
COPY . .
WORKDIR "/src/MainApplication"
RUN dotnet build "MainApplication.csproj" -c Release -o /app/build

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

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

VisualStudio 中,只需右键单击您的项目 Add--&gt;Docker Support 即可重新创建您的 docker 文件。

【讨论】:

  • 严肃的问题。为什么使用 3.1-buster-slim 而不是 3.1?我不明白-slim。我知道 buster 是一个特定的发行版,但我又何必在意呢?
  • 您可以使用任何其他 3.1 图像代替,甚至可以自己制作,但此图像是 Visual Studio 推荐的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-11
  • 2021-01-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多