'Cannot access API on Postman or Browser by running docker container on Port 8080
I have a simple API which I am running in Docker
When I run the command to run my image I get the output below
PS C:\Users\harili\GoodFood-backend> docker run -p 8080:80 --name container-backend-goodfood image-backend-goodfood
{"EventId":60,"LogLevel":"Warning","Category":"Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository","Message":"Storing keys in a directory \u0027/root/.aspnet/DataProtection-Keys\u0027 that may not be persisted outside of the container. Protected data will be unavailable when container is destroyed.","State":{"Message":"Storing keys in a directory \u0027/root/.aspnet/DataProtection-Keys\u0027 that may not be persisted outside of the container. Protected data will be unavailable when container is destroyed.","path":"/root/.aspnet/DataProtection-Keys","{OriginalFormat}":"Storing keys in a directory \u0027{path}\u0027 that may not be persisted outside of the container. Protected data will be unavailable when container is destroyed."}}
{"EventId":35,"LogLevel":"Warning","Category":"Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager","Message":"No XML encryptor configured. Key {f3c716ee-bcbe-4357-ba6e-3fcdbb6b9817} may be persisted to storage in unencrypted form.","State":{"Message":"No XML encryptor configured. Key {f3c716ee-bcbe-4357-ba6e-3fcdbb6b9817} may be persisted to storage in unencrypted form.","KeyId":"f3c716ee-bcbe-4357-ba6e-3fcdbb6b9817","{OriginalFormat}":"No XML encryptor configured. Key {KeyId:B} may be persisted to storage in unencrypted form."}}
{"EventId":14,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Now listening on: http://[::]:80","State":{"Message":"Now listening on: http://[::]:80","address":"http://[::]:80","{OriginalFormat}":"Now listening on: {address}"}}
{"EventId":0,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Application started. Press Ctrl\u002BC to shut down.","State":{"Message":"Application started. Press Ctrl\u002BC to shut down.","{OriginalFormat}":"Application started. Press Ctrl\u002BC to shut down."}}
{"EventId":0,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Hosting environment: Production","State":{"Message":"Hosting environment: Production","envName":"Production","{OriginalFormat}":"Hosting environment: {envName}"}}
{"EventId":0,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Content root path: /app","State":{"Message":"Content root path: /app","contentRoot":"/app","{OriginalFormat}":"Content root path: {contentRoot}"}}
However, I get connection refused when using Postman (even on browser)
http://localhost:8080/api/v1/Authentication/test (it's a get http request)
public IActionResult Test()
{
return Ok(new { Test = "it works test"});
}
Any idea what is wrong?
My docker file is:
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 ["GoodFood.Api/GoodFood.Api.csproj", "GoodFood.Api/"]
COPY ["GoodFood.Library/GoodFood.Library.csproj", "GoodFood.Library/"]
RUN dotnet restore "GoodFood.Api/GoodFood.Api.csproj"
COPY . .
WORKDIR "/src/GoodFood.Api"
RUN dotnet build "GoodFood.Api.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "GoodFood.Api.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "GoodFood.Api.dll"]
As you can see I am exposing port 80 above
There the command I use to run my container :
docker run -p 8080:80 --name container-backend image-backend
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
