© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
27 replies
Patricius

Dockerized .NET8 API not accessible.

When I try curl I get "(56) Recv Failure. Connection refused by peer."

Docker compose
version: '2.27'
services:
  api:
    build:
      context: ./server
      dockerfile: Dockerfile
    container_name: "dotnet_api"
    restart: always
    labels:
      - "author=${AUTHOR}"
      - "project=${SLUG}"
    ports:
      - "8080:8080"
    environment:
      ConnectionStrings__DefaultConnection: "server=db;userid=${MYSQL_USER};password=${MYSQL_PASSWORD};database=${MYSQL_DATABASE};"
      ASPNETCORE_ENVIRONMENT: "Development"
      ASPNETCORE_URLS: "http://+:8080"
version: '2.27'
services:
  api:
    build:
      context: ./server
      dockerfile: Dockerfile
    container_name: "dotnet_api"
    restart: always
    labels:
      - "author=${AUTHOR}"
      - "project=${SLUG}"
    ports:
      - "8080:8080"
    environment:
      ConnectionStrings__DefaultConnection: "server=db;userid=${MYSQL_USER};password=${MYSQL_PASSWORD};database=${MYSQL_DATABASE};"
      ASPNETCORE_ENVIRONMENT: "Development"
      ASPNETCORE_URLS: "http://+:8080"


Dockerfile
ARG DOTNET_IMAGE=mcr.microsoft.com/dotnet/sdk:8.0
FROM $DOTNET_IMAGE AS base
WORKDIR /usr/src/app

FROM base AS dependencies
COPY *.csproj ./
RUN dotnet restore

FROM base AS development
COPY --from=dependencies /usr/src/app/*.csproj ./
COPY . .
RUN dotnet build -c Debug -o out
EXPOSE 8080

ENTRYPOINT ["dotnet", "watch", "run", "--project", "server.csproj"]
ARG DOTNET_IMAGE=mcr.microsoft.com/dotnet/sdk:8.0
FROM $DOTNET_IMAGE AS base
WORKDIR /usr/src/app

FROM base AS dependencies
COPY *.csproj ./
RUN dotnet restore

FROM base AS development
COPY --from=dependencies /usr/src/app/*.csproj ./
COPY . .
RUN dotnet build -c Debug -o out
EXPOSE 8080

ENTRYPOINT ["dotnet", "watch", "run", "--project", "server.csproj"]


What I already tried:
- Running it outside Docker, it works.
- Running curl commands inside Docker, they work.
- Made sure that my app listens to port 8080.
- Changing port from 5282 to 8080. Port 5282 now gets failure 7, 8080 now gets error 56 similarly to what 5282 was getting. "Recv failure. Connection refused by peer."
- Researched online, from what I understand this issue is .NET8 specific and has to do with "Kestrel" not allowing traffic from outside of local device.

I am just using the weatherforecast template, so I have not written any code yet. I am on MacOS Sonoma 14.5 if that helps.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Make my api accessible
C#CC# / help
3y ago
✅ .net8 impersonate
C#CC# / help
2y ago
MudBlazor on net8, MudSelect not working
C#CC# / help
3y ago
Net8 Blazor onclick="js()" Not Working
C#CC# / help
3y ago