Patricius
Patricius
Explore posts from servers
CC#
Created by Patricius on 6/13/2024 in #help
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.
28 replies