Not able to contact container when run with port forwarding

Hi, I create a linux container in docker desktop in win 10 machine which is up and running and getting an IP (when I do investigate) as follows

"Gateway": "172.17.0.1",
		"GlobalIPv6Address": "",
		"GlobalIPv6PrefixLen": 0,
		"IPAddress": "172.17.0.4",

I run the container with the following command
docker run -p 8081:5000 eliassal/colourapi

When I try to access the web page with http:'//localhost:8081 or try to ping the IP 172.17.0.4 it just dont go through.

what is strange is that when I check Resources > Network, I see that docker desktop uses 192.168.65.0/24 subnet which is completly different from the IP of the container.

I visited the “Exec” tab and discovered that curl is not available, I tried to install it but it seems thcontainer is not able to reach the internet as well.

So how this can be resolved? Thanks in advance

Since the containers are running in the virtual machine of Docker, you won’t be able to ping the container IPs and the IP or subnet of the Docker Desktop environment is not really relevant here unless you have the same or colliding subnet in your LAN. Interestingly, I tried that too and I still had no network issue on macOS.

You can still try to change the subnet of Docker dEsktop, if you want.

Please, share the error message which makes you think that.

And also any error message or sign that you got when trying to access the container on localhost using the forwarded port.

One idea until you share more info: Your service in the container has to listen on 0.0.0.0, not a local IP, not localhost.

Here copy of my config for the app which *:80 which means any ip

Here is the error message when I try to access the web site from host

When I inspect the container, I get its IP

I try to access directly the web using the IP

when I checjk container port it seems OK

docker port 56a014192ff6

image

Please, don’t share screenshots of texts

Hard to read, impossible to quote.

I guess it is this config:

but I don’t see how it handles the IP. Not important if you can test the URL from inside the container. If it doesn’t have curl, you can try wget.

If the APP doesn’T return a response, it is an application issue, not a Dockr issue.

Empty response probably means the port mapping worked. You can test it by stopping the container and reloading the page. But what is “salam7” in the URL? Why isn’t it localhost?

I’m not sure what you mean by it. My previous question was about the internet access of the container. How is the container IP relevant, since you would not be able to access it from the host?

Thanks rimelek, yes it is an issue with the application. I created a new project in visual studio, after compiling and creating a container I was able to access the API in the container.
For the 1st app, I posted the issue to Visual studio support forum.
But tell me please, why it is not possible to ping the container? This the 1st thing to do to check connectivity, how can we check connectivity of a container when there is an issue? 2nd, I still dont understand why in settings of docker desktop it is indicated 192.168.65.0/24 subnet but my containers get IPs in the 172.17.0.0 subnet. Does this mean that this setting is not considered and docker attributes the subnet that it choses internally. When you say “You can still try to change the subnet of Docker Desktop”, this will not be useful as docker is not taking it into consideration, NO?

I added PosrtNavigator extension, when visiting it it shows so many 172
subnets!
How and when those subnets are created? Thanks

1 Like

That’s not how things are done in the container world, especially not with Docker Desktop, where the docker engine runs in a utility vm within a natted network. How do you expect to ping an ip where no route points to it? Traffic into the utility vm is handled by port forwarding, the same is true from the docker engine inside the utility vm to a container in a container network.

Both are correct. The first is the subnet the WSL2 utility vm works in, the 2nd in the subnet of the default docker network. You can list them with docker network ls, and inspect their details with docker network inspect <networkname> (of course <networkname> is just a placeholder).

It is useful when experience a collision between the ip range of your host network, and the network wsl uses.

Whenever you create a docker network. For instance every new docker compose deployment creates at least one default network, and all other networks you might have added as well.

So many thanks for all this explanation. But a natted network can connect to internet, no?

Yes, as you can also use a computer at home behind your home router and still access the internet. It wouldn’t be really useful if the way Docker Desktop works didn’t allow internet access :slight_smile:

but I still don’t know why you say you have no internet access. Excuse me if I missed where you replied to that part of my previous question or if I misunderstood something.

It is possible that the internet access doesn’t work, as it happened to some people, but usually caused by a proxy or VPN. I think you only showed what you saw when you tried to access the container so far.