'Use Visual Studio 2022 Create .net core 6.0 web api,Can't access api on docker
Use Visual Studio 2022 Create .net core 6.0 web api. it's work on the Visual Studio with debug use in docker. but when i create img and use the img create docker container.i can't access the .net core web api.
just defalut project.
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseAuthorization();
app.MapControllers();
app.Run();
use VS create default dockerfile,it's work on VS.
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["file-api/file-api.csproj", "file-api/"]
RUN dotnet restore "file-api/proever-file-api.csproj"
COPY . .
WORKDIR "/src/proever-file-api"
RUN dotnet build "file-api.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "file-api.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "file-api.dll"]
http://localhost:4433/GetWeatherForecast,i got http error 404
Solution 1:[1]
Your Docker Container is exposed to port 80! Try the following instand:
http://localhost/weatherforecast
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | pg-co |
