0

Docker beginner here.

I created a simple asp.net web application , which on run shows me the default page of application.

Using the docker build command, I create a image out of it and further using the docker run command docker run -d --name {containername} -p 81:8080 {imageid}. Now when I try to access the container image over local host on browser i.e. http://localhost:81/, I am getting 'The site cannot be reached' error. I expected the same default page of application to open over the exposed port 81.

My docker client is windows/amd and docker server is linux/amd. The docker version I am using is 19.03.08

Using docker inspect I could see

"PortBindings": {
                "8080/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "81"
                    }
                ]
            },

and "IPAddress": "" in networksettings.

docker ps and docker ps -a

I would appreciate any help or suggestion.

user2700022
  • 489
  • 3
  • 19
  • Does `http://127.0.0.1:81/` work? – chash May 06 '20 at 14:22
  • @hmm No, same issue. – Ranjit Mattamal May 06 '20 at 14:39
  • on which port you application is running, I do not think its 8080? – Adiii May 06 '20 at 15:14
  • Are you using Docker Toolbox on Windows, or the Docker Desktop application? When you start the application, does it print a "listening on..." message? – David Maze May 06 '20 at 15:19
  • @Adiii and David Maze : After a few changes in Docker file now I am able to get the container in running state. I can see the same(container in running state) in docker desktop. Also, the port 8080 is exposed(see image in link).. Though even now I am getting "The page isn't working. Localhost didn't send any data" error. [link]https://imgur.com/a/JY74TAL – Ranjit Mattamal May 06 '20 at 16:52

1 Answers1

1

From the screen shots attached, it seems your container is killed as soon as its started. You should have a process running in the container to keep it up & running. Only then will you be able to access via the host ip:port In this case http://localhost:81

In your docker ps -a the status is exited. Ideally it should be something like this if your container is up & running.

docker ps

CONTAINER ID        IMAGE                        COMMAND                CREATED              STATUS              PORTS               NAMES
4c01db0b339c        ubuntu:12.04                 bash                   17 seconds ago       Up 16 seconds
user2700022
  • 489
  • 3
  • 19
  • Thanks. I got the container in running state and is no longer exiting immediately. But when I view it in browser I get "This page isnt working. localhost didnt send any data". https://imgur.com/a/JY74TAL – Ranjit Mattamal May 06 '20 at 16:56
  • Try logging in to your container shell with `docker exec -it containerid bash` , this will take you into container shell. Try checking your process is running there as expected and try netcat to your container port, `nc -zv localhost 8080` – user2700022 May 06 '20 at 17:40