Search code examples
.netdockermodel-view-controllerdockerfiledocker-container

No available resource after deploy on docker my app


I containerize my app by using docker and after deploy I encounter problem with missing resources - no css and js files.

enter image description here

docker compose file:

  my-app:
    image: my-app-img
    container_name: my-app
    restart: always
    ports:
      - "80:80"

dockerfile

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build-env
WORKDIR /MyApp

COPY . ./

FROM mcr.microsoft.com/dotnet/aspnet:7.0
WORKDIR /MyApp
COPY --from=build-env /MyApp/out .
ENTRYPOINT ["dotnet", "MyApp.WebUI.dll']

the links in layout

    <script src="~/lib/jquery/dist/jquery-3.2.1.slim.min.js"></script>
    <script src="~/lib/popper.min.js"></script>
    <script src="~/lib/bootstrap/dist/js/bootstrap.min.js"></script>
    <script src="~/lib/jquery/dist/jquery.min.js"></script>
    <script src="~/js/site.js" asp-append-version="true"></script>

in program.cs im using the

app.UseStaticFiles();


Solution

  • I found solution for my issue

    for ex.

    var app = builder.Build();
    
    app.UseStaticFiles();
    
    DbHelpers.CreateDbIfNotExists(app);
    
    // Configure the HTTP request pipeline.
    if (!app.Environment.IsDevelopment())
    {
        app.UseExceptionHandler("/Metrics/Error");
        // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
        app.UseHsts();
    }
    
    app.UseHttpsRedirection();
    
    app.UseRouting();
    
    app.UseAuthorization();
    
    app.MapControllerRoute(
        name: "default",
        pattern: "{controller=Metrics}/{action=Index}/{id?}");
    
    app.Run();
    

    I moved the app.UseStaticFiles under our obj app, before that it was placed between app.usehttps / app.UseRouting and that caused this problem.