我在.net核心中创建了Web应用,并在我的应用和SqlServer中添加了docker-compose。然后我创建了控制台应用程序执行迁移数据库。但是,当我在日志中启动docker-compose时,我看到
The specified framework can be found at:
- https://aka.ms/dotnet-core-applaunch?framework=Microsoft.AspNetCore.App&framework_version=3.1.0&arch=x64&rid=debian.10-x64
It was not possible to find any compatible framework version
The framework 'Microsoft.AspNetCore.App', version '3.1.0' was not found.
- No frameworks were found.
You can resolve the problem by installing the specified framework and/or SDK.
但是我有.Net core SDK 3.1.0,我的Web应用程序正在使用它。
我的docker-compose看起来像这样:
version: '3.4'
services:
productmanagment.api:
image: ${DOCKER_REGISTRY-}productmanagmentapi
container_name: web
build:
context: .
dockerfile: ProductManagment.Api/Dockerfile
depends_on:
- db
- migrator
db:
image: "mcr.microsoft.com/mssql/server"
environment:
SA_PASSWORD: "MyPassword"
ACCEPT_EULA: "Y"
migrator:
image: ${DOCKER_REGISTRY-}productmanagmentmigrator
container_name: migrator
build:
context: .
dockerfile: ProductManagment.Migrator/Dockerfile
depends_on:
- db
environment:
DbConnection: "Server=db;Database=ProductManagment;User=sa;Password=MyPassword"
和Migrator中的Dockerfile(控制台应用程序)
FROM mcr.microsoft.com/dotnet/core/runtime:3.1-buster-slim AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["ProductManagment.Migrator/ProductManagment.Migrator.csproj", "ProductManagment.Migrator/"]
COPY ["ProductManagment.Api.csproj", "ProductManagment.Api/"]
RUN dotnet restore "ProductManagment.Migrator/ProductManagment.Migrator.csproj"
COPY . .
WORKDIR "/src/ProductManagment.Migrator"
RUN dotnet build "ProductManagment.Migrator.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "ProductManagment.Migrator.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ProductManagment.Migrator.dll"]
如何正确运行此控制台应用程序以及如何检查其日志?
根据收到的错误消息,您只需要将migrator应用程序的基本映像从mcr.microsoft.com/dotnet/core/runtime:3.1-buster-slim
更改为mcr.microsoft.com/dotnet/core/aspnet:3.1
。在没有看到项目代码的情况下,很难说出为什么需要进行此更改。
此Microsoft文档还应有助于提供一些见解:https://docs.microsoft.com/en-us/dotnet/core/docker/build-container?tabs=windows