Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue Running EF Core Migration Bundle in .NET SDK Container Image on Linux Debian (WSL2) #34979

Open
louisosullivan opened this issue Oct 25, 2024 · 0 comments

Comments

@louisosullivan
Copy link

louisosullivan commented Oct 25, 2024

I'm using the .NET SDK to build a container image for a Blazor Web App, and I'm running it on Docker Desktop with WSL2 for local development. My goal is to generate an Entity Framework Core migration bundle during the build process and include it in the container image, then execute the bundle as part of the entrypoint.

csproj Configuration

Here's a relevant excerpt from my .csproj file:

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <RuntimeIdentifiers>linux-x64</RuntimeIdentifiers>
    <EnableSdkContainerDebugging>True</EnableSdkContainerDebugging>
    <ContainerBaseImage>mcr.microsoft.com/dotnet/aspnet:8.0</ContainerBaseImage>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\..\MyApp.Infrastructure\MyApp.Infrastructure.csproj" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.8" />
  </ItemGroup>

  <Target Name="BuildEfCoreMigrationBundle" AfterTargets="Publish">
    <Exec WorkingDirectory="$(SolutionDir)" Command="dotnet ef migrations bundle --self-contained --runtime linux-x64 --project MyApp.Infrastructure --startup-project MyApp.BlazorWebapp\MyApp.BlazorWebApp --output $(PublishDir)\efbundle --force" />
  </Target>

  <ItemGroup>
    <ContainerFile Include="$(PublishDir)\efbundle" TargetPath="efbundle" />
  </ItemGroup>
</Project>

Docker Compose Configuration

My docker-compose.yml file is set up as follows:

services:
  myapp.blazorwebapp:
    image: ${DOCKER_REGISTRY-}myappblazorwebapp
    container_name: MyApp.BlazorWebApp
    environment:
      - ASPNETCORE_Kestrel__Certificates__Default__Password=mysecurepassword
      - ASPNETCORE_Kestrel__Certificates__Default__Path=/https/MyApp.BlazorWebApp.pfx
      - ASPNETCORE_URLS=http://+:80;https://+:443
      - ASPNETCORE_ENVIRONMENT=Development
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - C:\Temp\https\MyApp.BlazorWebApp.pfx:/https/MyApp.BlazorWebApp.pfx
    entrypoint:
      bash -c "./efbundle; dotnet MyApp.BlazorWebApp.dll"

The Problem

The container crashes when it tries to execute ./efbundle, giving the following error message:
2024-10-25 10:20:31 <3>WSL (8) ERROR: UtilGetPpid:1279: Failed to parse: /proc/1/stat, content: 1 (bash) S 0 1 1 0 -1 4194560 566 84 23 3 1 0 0 0 20 0 1 0 1377133 4018176 690 18446744073709551615 94520745209856 94520745999261 140723308442128 0 0 0 65536 4 65538 1 0 0 17 19 0 0 0 0 0 94520746232560 94520746280804 94520777572352 140723308445123 140723308445198 140723308445198 140723308445674 0

If I remove the efbundle from the entrypoint, the container runs successfully, and I can access the Blazor app.

Troubleshooting Steps

  1. Debian VM Test: I tried running ./efbundle in a Debian 12 (Bookworm) VM and initially received a permission error. Running chmod +x efbundle resolved the permission issue, but I then encountered the following error:
    bash: ./efbundle: cannot execute binary file: Exec format error
  2. Environment Details:
    WSL Version: WSL2
    Container Base OS: Debian GNU/Linux 12 (Bookworm)
    .NET SDK Target Runtime: linux-x64
    EF Core Version: 8.0.8

Questions

  1. Why does the efbundle file fail to execute, even after setting executable permissions? Is there an issue with the file format or target runtime that I'm overlooking?
  2. Is it possible to resolve the permissions issue within the .NET SDK-based container configuration without reverting to a Dockerfile? If not, what would be the recommended way to include and execute the migration bundle? I have seen a similar solution using a Dockerfile here and it looks like permissions are being set so their bundle file and script can be executed.

This is my first time using GitHub so apologies if the question formatting is off.

Any insights or suggestions would be greatly appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant