I have a sample helloworld asp.net core MVC application hosted in linux docker. The docker image is based on
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
After building the image and running the Image in a container, I can see the container running and listening 8080 port on the docker host.

but I am unable to access the website using the URL
http://192.168.0.100:8080
As part of debugging, I analyzed the response header using curl from the docker host (Linux machine in which docker is running)

got the same response from docker container (172.17.0.2 being the IP of the docker

I wondered if any firewall is blocking request to port 8080, to check that I got the status of UFW.

can someone please tell me what I am missing.
Update 1: I deployed the website outside the docker and it is working fine but not accessible outside the Linux box since it is hosted in Kestrel. I install Nginx and configured to reroute requests and the website now because accessible outside the Linux box also.
Now is it because the application would have hosted in kestrel in docker container also the reason why I am not able to access the site when hosted in the container.
I think you're just having a mismatch between Kestrel (or Nginx) serving on 8080 in the container, vs. the host's exposed port (80, per your configuration above). As it is right now I would expect to get a 404 on both ports 80/8080 for the docker host, since 8080 isn't exposed, and 80 doesn't have anything mapped to it.
You'll need to add a flag when configuring the container, perhaps something like --publish 80:8080, which would map TCP port 8080 in the container to port 80 on the Docker host.
Check out the docs on published ports for more details.
As I remeber if you attempt to access to your app via url like http://192.168.0.100:8080 you should run container in host network (docker run ... --net host ...), if so this should work. By default all apps running in container with dridged network. Actually you should try access by container ip: 172.17.0.2 or you actual container ip (to see details about network run shell docker <container_id>) and access to app via: 172.17.0.2:8080). In bridge network mode you can't access to 8080 on you machine ip you either should adjust routing between interfaces via iptables if you are on a linux or properly set up windows firewall in you are running it from windows. The second way is to configure proxy on you web server to pass requests from you local machine ip + 8080 port, on docker container ip + port. But if you bind 8080 for you proxy server you can'not use it for port mapping in container.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With