Docker container is not connecting to the external system

Within the docker container, the external system is not accessible even the curl command is unable to find the host. I’m running docker on windows11 with WSL2.
I have intentionally changed the IP address and port and here is the error message:

ERMINAL PORTS
* connect to 182.18.92.49 port 3094 failed: No route to host
* Failed to connect to 182.18.92.49 port 3094 : No route to host
Closing connection
curl: (7) Failed to connect to 182.18.92.49 port 3094 : No route to host
# curl -v http://182.18.92.49:3094 /api/ServiceAlpha
*
Trying 182.18.92.49:3094 ...
* connect to 182.18.92.49 port 3094 failed: No route to host
* Failed to connect to 182.18.92.49 port 3094 : No route host
* Closing connection >
curl: (7) Failed to connect to 182.18.92.49 port 3094 : No route to host # |

Can anyone please help?

@Docker any help on it?

The lack of answers so far could be caused at least partially by the lack of proper formatting in your message. I fixed it, but please make sure next time you format the shared code as described in the formatting guide which uses MarkDown as almost any technical forums, including GitHub:

The issue indicates routing problems which can happen when using a VPN or proxy. Instead of using a public IP address, you could try to access a LAN IP if you have one or use host.docker.internal instead of the IP address. host.docker.internal will route the traffic to the localhost of the your Windows host so whatever service you want to access, has to listen on localhost as well.

PS.: Mentioning the Docker staff will not really get you quicker answers :slight_smile: we are not in that group, but if you feel we forgot about your question, a sending a new post is enough to get the topic to the list of recent topics again.

Thanks for your help @rimelek. Connection to localhost through host.docker.internal is working fine but the error comes when it goes to connect to some domain or the db server hosted on the other machine.

Can you access the internet from the containers?

I have installed curl within the container and executed the following command:

curl -X GET "https://fakerestapi.azurewebsites.net/api/v1/Activities" -H  "accept: text/plain; v=1.0"

And it is giving me the response without any issue but the connection to the required domain is not building. The strange thing is that the URLs are accessible on my local machine and I have also tried to run the container on the VDI and faced the same connection issue.

I have also installed ping and here is the command with the output:

docker exec -it cronapi ping www.example.com
PING www.example.com (182.19.55.77) 56(84) bytes of data.
From 28461e455f2b (182.19.0.2) icmp_seq=1 Destination Host Unreachable

Here is an image you can use for debugging network issues

You can find example commands as well. I asked about the internet connection because I suspected you have a firewall, router, anything that blocks the connection when comming from your network and wants to go back. I’m not a network expert, I can’t guide you through as it would be hard enough even if I were there, but if outgoing connections work, the problem must be in your network. You can check the connection from windows, from a virtual machine and from a container in a vitual machine. In the meantime, you can try to watch the network traffic. Sometimes traffic goes to different gateways from different machines (VM, physical) and some can block certain kind of traffic while some will let it through. Or simply the IP address you try is not accessible from the gateway where the traffic went.

I know, it is not a lot, but I’m affraid I won’t be able to help much more.