Create cloud-native apps Training - cannot connect to backend service

Grzegorz Jurek 20 Reputation points
2024-09-05T12:13:17.1333333+00:00

Hi

After I've completed nearly all from here: [https://learn.microsoft.com/en-us/training/modules/dotnet-microservices/3-exercise-build-docker-image?source=learn] I did stuck on the "Run the container and test the service" part. When I open PORTS tab and click Open in Browser on the "backend" the web browser is starting and web page is loading infinitely and I can see in the Dev Containers log that my connection is refused:

[531969 ms] rejected promise not handled within 1 second: Error: connect ECONNREFUSED 127.0.0.1:32001 stack trace: Error: connect ECONNREFUSED 127.0.0.1:32001 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1606:16) [11:58:02] Error: connect ECONNREFUSED 127.0.0.1:32001 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1606:16) { errno: -111, code: 'ECONNREFUSED', syscall: 'connect', address: '127.0.0.1', port: 32001 }

I tried to set firewall rules in Windows to allow both 32000 and 32001 ports but with no effect.

I'm running it on Windows 10

Does anyone know how to fix it?

Edit: I figured out that using local ip address:port of my machine instead of localhost:port actually works.

Viva Learning
Viva Learning
A Microsoft Viva module that provides employees with formal and informal learning.
105 questions
{count} votes

Accepted answer
  1. Pradeep M 4,015 Reputation points Microsoft Vendor
    2024-09-06T03:57:50.7533333+00:00

    Hi Grzegorz Jurek,

    It seems the issue you're experiencing is related to how Docker or the Dev Containers environment is mapping ports to localhost, causing the "connection refused" error. Since you've mentioned that accessing the service via your local IP address works, this indicates that the issue likely lies with the port mapping for localhost. Here are a few suggestions that may help: 

    1.Continue using your local IP address: As you've discovered, using the local IP (<local-ip>:32001) resolves the issue. This suggests that the port mapping to localhost is not functioning correctly. Using the IP address directly is a valid workaround and should work for testing purposes. 

    2.Check Docker network settings: In some cases, Docker might not expose ports correctly to localhost. If you're on Linux, you can try running Docker with the --network host option, but this isn't supported on Windows. For your case, continuing to use the local IP address seems to be the best option. 

    3.Review Windows Firewall or Docker configuration: Since you are using Windows, ensure that Docker Desktop is properly configured to expose ports and that your firewall settings allow Docker to map ports as needed. It might be necessary to adjust your firewall settings to allow Docker traffic through specific ports. 

    4.Verify port availability: You can use the netstat -an command or a tool like nmap to check if port 32001 is open and listening on localhost. If the port isn’t listed, this could explain why the connection is being refused. 

    Since using the local IP address works for you, I would suggest continuing with that method for now. If you wish to fully resolve the localhost issue, reviewing your Docker network configuration could provide additional insights. 

    Let me know if you need further assistance 

    If you have found the answer provided to be helpful, please click on the "Accept answer/Upvote" button so that it is useful for other members in the Microsoft Q&A community.        

    Thank you. 

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.