Docker container host port not working but working in the container port

Viewed 649

I am Not getting Output in the exposed port but got the output in the container port in the Docker container's shell. I am not able to find the root cause behind it.

I am using docker in a windows container environment.

I have created a docker image using the below docker file.

FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8-windowsservercore-ltsc2019

COPY ./PublishOutput/ /inetpub/wwwroot

# Give Full Access To Folder
RUN icacls 'c:/inetpub/wwwroot' /grant 'Everyone:(OI)(CI)F'
# Check that the files have been successfully copied
RUN dir 

Create an image below command:

docker build -t projectimage .

After creating the image Details:

REPOSITORY    TAG     IMAGE ID       CREATED       SIZE
                 
projectimage  latest  4654c6606bbd   4 days ago    9.06GB

From the above image, I have created a docker container.

Create a container below command:

docker container run -d -p 8080:80 -–name projectcontainer projectimage

After creating the container Details:

CONTAINER ID   IMAGE          COMMAND                   CREATED         STATUS              PORTS                  NAMES
73abe46e99e9   projectimage   "C:\\ServiceMonitor.e…"   2 minutes ago   Up About a minute   0.0.0.0:8080->80/tcp   projectcontainer

Now, I go to the browser and try to access the container using the exposed port i.e 8080

http://localhost:8080

I get the "404 - File or directory not found." output on the browser screen. below is the screenshot of the browser output. screenshot of the browser output

NetWork Details of container:

 "NetworkSettings": {
        "Bridge": "",
        "SandboxID": "73abe46e99e9231b2d3ae67c436220e789b84990499b853310d4e9b1840b2118",
        "HairpinMode": false,
        "LinkLocalIPv6Address": "",
        "LinkLocalIPv6PrefixLen": 0,
        "Ports": {
            "80/tcp": [
                {
                    "HostIp": "0.0.0.0",
                    "HostPort": "8080"
                }
            ]
        },

Now, I go into the Docker container's shell using the command

docker exec -it projectcontainer cmd.exe

Inside the Docker container's shell, I try to access the container using the container port i.e 80

curl localhost:80

and I got my output " correctly configured to work" which is the Expected Output. below is the screenshot attached. Expected Output

So, why I am not getting the Expected output in the exposed port in the browser? How to Resolve this Problem.

Also, I am able to ping the host machine from the container and vice-versa.

Any assistance you can provide would be greatly appreciated.

0 Answers
Related