I have an ASP.NET web app that sends signal through can bus on Raspberry Pi. When I run the app throught dotnet run it runs flawlessly. I had to dockerize, and in order to have access to can bus I have to start the container with network=host parameter. Thing is, the app is supposed to start on certain port (8080 in this case). When I run it on my PC, with network=host, it's fine. But when I run it on Raspberry Pi, I get error that connection is refused in the browser, even though app logs in container say it starts on port 8080. What prevents the app from being accessible?
Here's dockerfile:
# 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"]
Here's program.cs if it makes any difference:
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<ICanBusService, CanBusService>();
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();