Software⏱️ 2 min read📅 2026-05-30

How to Fix: How to fix "Connection Refused" when accessing .NET 9 Web API in Docker

Docker container issues with ASP.NET Core 9 Web API connection refused error.

Quick Answer: Try exposing the port in the Docker run command or using a volume to map the host's IP address to the container's IP address.

To resolve the "Connection Refused" error when accessing your ASP.NET Core 9 Web API in Docker, it's essential to understand why this issue occurs. The problem lies in how Docker maps ports between the container and your host machine.

💡 Why You Are Getting This Error

  • The issue arises because the ASP.NET Core 9 Web API is listening on a non-standard port, which is not mapped to your host machine's default port.

🛠️ Step-by-Step Verified Fixes

Method 1: Exposing the Port in Dockerfile

  1. Step 1: In your Dockerfile, map the port from the container to your host machine by adding the following line: EXPOSE 8085

Method 2: Using Docker Compose with Port Mapping

  1. Step 1: In your docker-compose.yml, add the following configuration to map the port: version: '3'
    services:
      api:
        image: your-image-name
        ports:
          8085:8085

✨ Wrapping Up

By following these steps, you should be able to resolve the "Connection Refused" error and successfully access your ASP.NET Core 9 Web API in Docker.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions