Auf die ASP.NET Core-App im Docker-Container kann nicht zugegriffen werdenC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Auf die ASP.NET Core-App im Docker-Container kann nicht zugegriffen werden

Post by Anonymous »

Ich habe eine ASP.NET Core-Webanwendung, die Signale über den CAN-Bus auf dem Raspberry Pi sendet. Wenn ich die App über dotnet run ausführe, läuft sie einwandfrei. Ich musste dockerisieren und um Zugriff auf den CAN-Bus zu haben, muss ich den Container mit dem Parameter network=host starten. Die Sache ist, dass die App auf einem bestimmten Port (in diesem Fall 8080) starten soll. Wenn ich es auf meinem PC mit network=host ausführe, ist es in Ordnung. Aber wenn ich es auf dem Raspberry Pi ausführe, erhalte ich die Fehlermeldung, dass die Verbindung im Browser abgelehnt wird, obwohl die App-Protokolle im Container sagen, dass sie auf Port 8080 startet. Gibt es etwas Besonderes in der Raspberry-Konfiguration, das verhindern kann, dass auf die App zugegriffen werden kann?
Hier ist die Docker-Datei:

Code: Select all

# Stage 1: Build React App
FROM node:20 AS build-frontend
WORKDIR /app
COPY ClientApp/package*.json ./
RUN npm install
COPY ClientApp/ ./
RUN npm run build

# Stage 2: Build ASP.NET backend
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-backend
WORKDIR /src
COPY . .
RUN dotnet publish -c Release -o /app/publish

# Stage 3: Combine frontend and backend
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final
WORKDIR /app
COPY --from=build-backend /app/publish .
COPY --from=build-frontend /app/dist ./ClientApp
ENV ASPNETCORE_URLS=http://0.0.0.0:8080
ENV ASPNETCORE_ENVIRONMENT=Production
EXPOSE 8080
ENTRYPOINT ["dotnet", "ReefWebApp.dll"]
Hier ist die program.cs, falls es einen Unterschied macht:

Code: Select all

using Microsoft.AspNetCore.Builder;

var builder = WebApplication.CreateBuilder(args);

if (builder.Environment.IsProduction())
{
builder.Services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "ClientApp";
});
}

builder.Logging.AddConsole();
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddScoped();

var app = builder.Build();

if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

if (!app.Environment.IsProduction())
{
app.UseHttpsRedirection();
}

app.UseRouting();

app.UseAuthorization();

#pragma warning disable ASP0014 // Suggest using top level route registrations
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(name: "default", pattern: "{controller}/{action=Index}/{id?}");
});
#pragma warning restore ASP0014 // Suggest using top level route registrations

if (builder.Environment.IsProduction())
{
app.UseSpaStaticFiles();
}

app.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp";

if (app.Environment.IsDevelopment())
{
spa.UseProxyToSpaDevelopmentServer("http://localhost:5173");
}
});

app.Run();

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post