Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My ASP.Net Core website hosted in Linux docker is not reachable

Tags:

docker

nginx

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.

enter image description here

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)

enter image description here

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

enter image description here

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

enter image description here

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.

like image 981
Sujith Kp Avatar asked Dec 14 '25 04:12

Sujith Kp


2 Answers

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.

like image 113
Kurtis Jungersen Avatar answered Dec 16 '25 19:12

Kurtis Jungersen


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.

like image 24
Michael Ushakov Avatar answered Dec 16 '25 18:12

Michael Ushakov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!