0

I have written a docker file to build my .Net 5.0 web API, I am able to build it and push it, however, I am not able to access it.

My Docker File.

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app

EXPOSE 80

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build

WORKDIR /src

COPY ["API/WebUI/Summit.API.csproj", "API/WebUI/"]

COPY ["Application/Summit.Application.csproj", "Application/"]

COPY ["Domain/Shared/Summit.Domain.csproj", "Domain/Shared/"]

COPY ["Domain/SqlKata.Execution/SqlKata.Execution.csproj", 
"Domain/SqlKata.Execution/"]

COPY ["Domain/QueryBuilder/QueryBuilder.csproj", "Domain/QueryBuilder/"]

COPY ["Infrastructure/Summit.Infrastructure.csproj", "Infrastructure/"]

RUN dotnet restore "API/WebUI/Summit.API.csproj"

COPY . .

WORKDIR "/src/API/WebUI"

RUN dotnet build "Summit.API.csproj" -c Release -o /app/build


FROM build AS publish

RUN dotnet publish "Summit.API.csproj" -c Release -o /app/publish



FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS runtime

WORKDIR /app

COPY --from=publish /app/publish .

ENV ASPNETCORE_URLS http://*:6000

ENTRYPOINT ["dotnet", "Summit.API.dll"]

post building the solution, I am using the below command to create a container.

docker container run -itd --name WebAPIServer -p 6000:6000 image name.

but when I am trying to access it with http://localhost:6000 I am getting an error that this site can't be reached.

I am not using port 5000 because my docker registry is running on that port.

The container's log says:

ClientConnectionId:00000000-0000-0000-0000-000000000000 [05:58:37 WRN] Unable to bind to localhost:5000 on the IPv6 loopback interface: 'Cannot assign requested address'. [05:58:37 INF] Now listening on: localhost:5000 [05:58:37 INF] Application started. Press Ctrl+C to shut down. [05:58:37 INF] Hosting environment: Production [05:58:37 INF] Content root path: /app root@labubuntu20-01:/home/spaadmin#

Jeff
  • 265
  • 1
  • 4
  • What do the container's logs say? – Daniel Mann Sep 15 '21 at 04:35
  • You didn't `EXPOSE` port 6000. – Lex Li Sep 15 '21 at 04:42
  • I tried by exposing port 6000 but no luck – Chandra Shekhar Sep 15 '21 at 04:56
  • ClientConnectionId:00000000-0000-0000-0000-000000000000 [05:58:37 WRN] Unable to bind to http://localhost:5000 on the IPv6 loopback interface: 'Cannot assign requested address'. [05:58:37 INF] Now listening on: http://localhost:5000 [05:58:37 INF] Application started. Press Ctrl+C to shut down. [05:58:37 INF] Hosting environment: Production [05:58:37 INF] Content root path: /app root@labubuntu20-01:/home/spaadmin# – Chandra Shekhar Sep 15 '21 at 06:02
  • Above is the output i am getting when running command docker container logs container id. – Chandra Shekhar Sep 15 '21 at 06:02
  • Expose the port 5000 setups the `ENTRYPOINT` and run `docker container run -d --name WebAPIServer -p 6000:5000 image_name.` – Max Sep 15 '21 at 08:02
  • Hi @Max i have only one VM and on port 5000 already docker registry is running. – Chandra Shekhar Sep 15 '21 at 08:24
  • Please check this thread and add the code ENV ASPNETCORE_URLS=http://+:80 and other ENV : https://stackoverflow.com/questions/59657499/unable-to-bind-to-http-localhost5000-on-the-ipv6-loopback-interface-cannot – RahulKumarShaw Sep 15 '21 at 08:30
  • The command above map the container port 5000 to your port 6000. – Max Sep 15 '21 at 08:34

1 Answers1

1

Based on this error “Unable to bind to localhost:5000 on the IPv6 loopback interface: 'Cannot assign requested address”

To workaround the issue, add the code ENV ASPNETCORE_URLS=http://+:80 below the other ENV declarations at the top of the Dockerfile.develop file.

Open you vi Dockerfile and add the below ENV.

Dockerfile.develop after:

FROM mcr.microsoft.com/dotnet/core/sdk:3.1
ARG BUILD_CONFIGURATION=Debug
ENV ASPNETCORE_ENVIRONMENT=Development
ENV DOTNET_USE_POLLING_FILE_WATCHER=true  
ENV ASPNETCORE_URLS=http://+:80  
EXPOSE 80

Reference : Unable to bind to http://localhost:5000 on the IPv6 loopback interface: 'Cannot assign requested address'.

COPY ["Domain/SqlKata.Execution/SqlKata.Execution.csproj", 
"Domain/SqlKata.Execution/"]

Change the above statement to one single line it might be throw error for only argument is passing it should be like this

COPY ["Domain/SqlKata.Execution/SqlKata.Execution.csproj", "Domain/SqlKata.Execution/"]
RahulKumarShaw
  • 4,192
  • 2
  • 5
  • 11