'Docker: cannot open port from container to host

I'm using Docker for Mac. I have a container that run a server, for example my server is run on port 5000. I have exposed this port on Dockerfile

When my container is running, I connect to this container and check and if this server is working or not by running below command and see that it returns data (a bunch of html and javascript)

wget -d localhost:5000

Notes, I start this container and also publish port outside by command:

docker run -d -p 5000:5000 <docker_image_name>

But at docker host (is my mac and running El Capitan), I open chrome and go to address localhost:5000. It doesn't work. Just a little note, if I go to any arbitrary port such as localhost:4000 I see error message from chrome such as:

This site can’t be reached
localhost refused to connect.

But error message for localhost:5000 is:

The localhost page isn’t working
localhost didn’t send any data.

So it seems I have configured work "a little" but something wrong. Please tell me how to fix this.



Solution 1:[1]

I had this problem using Docker for Mac, trying to run an Angular2 app.

I fixed the issue by changing the start script in package.json to

"scripts": {
    "start": "ng serve --host 0.0.0.0"
}

Previously start was only ng serve.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 8888