Paul
Paul

Reputation: 3253

Cannot access API run via docker on Port 80 in Postman

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

docker run newapi:latest mee
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: http://[::]:80
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
      Content root path: /api

This all looks fine

However, I get connection refused when using Postman

http://localhost/weatherforecast

Any idea what is wrong?

My docker file is:

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /api

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

EXPOSE 80

# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /api
COPY --from=build-env /api/out .
ENTRYPOINT ["dotnet", "api.dll"]

As you can see I am exposing port 80

I can use http://localhost:8080 but I just want to be able to use http://localhost

Upvotes: 1

Views: 845

Answers (1)

d1Master
d1Master

Reputation: 152

When you run the docker try mapping the port

docker run -p 80:80 newapi:latest mee

Upvotes: 1

Related Questions