这是我的 docker compose 文件:
version: '3.4'
networks:
demonetwork:
services:
demoappdb:
container_name: app-db
image: mcr.microsoft.com/mssql/server:2019-latest
ports:
- 8002:1433
environment:
- ACCEPT_EULA=Y
- SA_PASSWORD=password@12345#
networks:
- demonetwork
lightcleanarchitecturewebapi:
container_name: lca-app
image: ${DOCKER_REGISTRY-}lightcleanarchitecturewebapi
build:
context: .
dockerfile: src/Web/Dockerfile
ports:
- 8081:8081
- 8080:8080
depends_on:
- demoappdb
environment:
- DB_HOST=demoappdb
- DB_NAME=DemoBlazorApp
- DB_SA_PASSWORD=password@12345#
networks:
- demonetwork
当我想运行迁移来创建数据库时,出现此错误:
2024-01-12 16:28:38 无法加载库 libgssapi_krb5.so.2
2024-01-12 16:28:38 错误:libgssapi_krb5.so.2:无法打开共享 目标文件:没有这样的文件或目录
context.Database.Migrate() 发生错误:
using (var serviceScope = app.ApplicationServices.CreateScope())
{
var context = serviceScope.ServiceProvider.GetRequiredService<T>();
context.Database.Migrate();
}
这是我的 Docker 文件:
# Use a Debian-based image with ASP.NET runtime
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER app
WORKDIR /app
EXPOSE 8081
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["src/Web/LightCleanArchitecture.WebApi.csproj", "src/Web/"]
COPY ["src/Application/LightCleanArchitecture.Application.csproj", "src/Application/"]
COPY ["src/Domain/LightCleanArchitecture.Domain.csproj", "src/Domain/"]
COPY ["src/Infrastructure/LightCleanArchitecture.Infrastructure.csproj", "src/Infrastructure/"]
RUN dotnet restore "./src/Web/./LightCleanArchitecture.WebApi.csproj"
COPY . .
WORKDIR "/src/src/Web"
RUN dotnet build "./LightCleanArchitecture.WebApi.csproj" -c $BUILD_CONFIGURATION -o /app/build
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./LightCleanArchitecture.WebApi.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "LightCleanArchitecture.WebApi.dll"]
此问题仅发生在 ASP.NET Core 8 上,它在 .NET 6 上正常工作。
我想我必须在我创建的 docker 映像上安装
libgssapi_krb5.so.2
,但我找不到如何做到这一点。
如果您有这方面的经验,请分享。
据我了解,这个错误导致我的程序崩溃, 但我在 catch 部分找不到任何异常错误。
2024-01-12 16:28:38 无法加载库 libgssapi_krb5.so.2
2024-01-12 16:28:38 错误:libgssapi_krb5.so.2:无法打开共享 目标文件:没有这样的文件或目录
我做了什么?我将基本映像从 aspnet:8.0 更改为 aspnet:8.0-jammy-amd64,进行此更改后,我可以在 catch 部分收到错误消息。
该错误与我的连接字符串有关,我必须添加此选项 “Trusted_Connection = false” 来解决此问题。