1

I have an ASP.NET Core 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. Is there anything specific in Raspberry configuration that can prevents the app from being accessible?

Here's the 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 the 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();
4
  • 1
    Yeah, it works on Pi when I start it without container, it works when I run it on bridge network (but it can't access can-bus then, since it's on host's network) and it works in container when running on host's network, but not on Pi, on my PC Commented Oct 31 at 18:17
  • Can you clarify further when it is that the app works? Does it work on the pi at all or does it only work on your PC? Also please add what you are using to run your docker image. Commented Oct 31 at 18:19
  • Could it be that the -p 8080:80 parameter when running your docker container is missing? Commented Oct 31 at 19:04
  • 2
    It has no use if network=host is used Commented Oct 31 at 19:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.