You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

DotNet Core 2.2 Docker Compose运行正常但浏览器无法访问

Troubleshooting Unreachable .NET Core 2.2 Service in Docker

Let's walk through the most likely issues and fixes for your scenario where your service appears to start but isn't accessible via browser or API calls:

1. Verify Port Mapping & Container Listening Port

Your docker-compose.yml maps host port 8080 to container port 80, but we need to confirm your .NET Core app is actually listening on port 80 inside the container:

  • Check your Dockerfile: Ensure you've set the ASPNETCORE_URLS environment variable to bind to all interfaces on port 80. Add this line to the base stage of your Dockerfile:
    ENV ASPNETCORE_URLS=http://+:80
    
  • Verify the container's listening ports: Run docker exec <your-container-id> netstat -tulpn (replace <your-container-id> with the ID of your onlinesm.logs container). You should see a dotnet process listening on 0.0.0.0:80.

2. Check App Startup Logs for Hidden Errors

Even if docker-compose up says the service is "running", there might be runtime errors preventing the app from accepting requests:

  • Pull the full logs for your service with:
    docker logs onlinesm.logs
    
    Look for exceptions (like database connection failures, missing configs, or startup errors) that might be stopping the app from fully initializing.

3. Test Network Connectivity Directly

Rule out port mapping or firewall issues:

  • Try accessing the service directly via the container's internal IP:
    1. Get the container IP with docker inspect onlinesm.logs | grep "IPAddress"
    2. Use curl <container-ip>:80 or a browser to hit that address. If this works, the issue is with port mapping on your host.
  • Check if your host firewall is blocking port 8080. Temporarily disable it (or add an inbound rule) to test.
  • Try using curl localhost:8080 from your host machine—sometimes browser caching or extensions can interfere with requests.

4. Validate Your Dockerfile Configuration

Make sure your Dockerfile is properly set up for .NET Core 2.2. A minimal working example looks like this:

# Base image for runtime
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS base
WORKDIR /app
EXPOSE 80
ENV ASPNETCORE_URLS=http://+:80

# Build stage
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
WORKDIR /src
COPY ["YourApp.csproj", "./"]
RUN dotnet restore "./YourApp.csproj"
COPY . .
RUN dotnet build "YourApp.csproj" -c Release -o /app/build

# Publish stage
FROM build AS publish
RUN dotnet publish "YourApp.csproj" -c Release -o /app/publish

# Final runtime image
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "YourApp.dll"]

Replace YourApp.csproj and YourApp.dll with your actual project names.

5. Check Container Health Status

Confirm your container isn't silently restarting:

  • Run docker ps and look at the STATUS column for onlinesm.logs. If it shows Restarting (x) ..., that means the app is crashing repeatedly—check the logs (step 2) for the root cause.

内容的提问来源于stack exchange,提问作者mmffggss

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 04:02:40