Getting 'ERR_CONNECTION_REFUSED' when trying to browse port mapped to Docker container
Solution 1
Finally figured out how to make this work!
I'm running Docker on MacOS and using 'Docker QuickStart Terminal'.
Turns out, navigating to 'localhost', '127.0.0.1', etc. was wrong, because it looks like Docker sets up its own host:
## .
## ## ## ==
## ## ## ## ## ===
/"""""""""""""""""\___/ ===
~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ / ===- ~~~
\______ o __/
\ \ __/
\____\_______/
docker is configured to use the default machine with IP 192.168.99.100
For help getting started, check out the docs at https://docs.docker.com
When I use 192.168.99.100
, given above, everything works fine.
Solution 2
To find out the IP address of the running container, you can use:
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' myContainerID
Related videos on Youtube
![jonathanconway](https://i.stack.imgur.com/X2Gct.jpg?s=256&g=1)
jonathanconway
Hello, I'm Jonathan! 👋 Experienced in Front End Development (HTML, CSS, ES6, Angular, React), Back End Development (C#, Java, NodeJS) and Software Engineering (OOP, RDBMS, TDD and beginning to branch into FP). Additionally trained and experienced in Interaction Design (User Research, Sketching, Wireframing, Prototyping, Accessibility). Focused on user needs, with an emphasis on relationships, empathy, evidence and results. I enjoy working in diverse, multi-disciplinary teams, learning and sharing knowledge. Made significant and lasting contributions to several high-impact projects in Australia, for: Bupa (2010), Westpac (2013), Service NSW (2015) and the Digital Transformation Agency (2017). Worked remotely for 5+ clients (including production support and across time-zones), with high self-motivation, productivity and communication (over email, IM and pull-requests). • Continuously programming since 2000 •
Updated on September 18, 2022Comments
-
jonathanconway almost 2 years
I have pulled a Docker image:
$ docker pull ghost
And run a container from the image:
$ docker run --name test-ghost -p 8080:2368 -d ghost 7d984e974f6a75fe18b3d397b5c8f0a428928a2be9df83f0d61a679aa5f537fc
My understanding is that the
-p
switch will map a port on the host (8080) to a port inside Docker (2368), so that I can hit the web server running within Docker, from outside docker, i.e. from my host.However, when I try to browse to any of the following addresses in Chrome, from my host:
http://localhost:8080/ http://0.0.0.0:8080/ http://127.0.0.1:8080/
I get the following error:
This webpage is not available ERR_CONNECTION_REFUSED
This seems like it might be a connectivity issue, rather than a problem inside the container, as when I inspect the running processes inside the container, it appears that NodeJS is running:
$ docker top test-ghost UID PID PPID ... CMD docker 4290 1028 ... npm docker 4324 4290 ... sh -c node index docker 4325 4324 ... node index
But it appears nothing is listening on port 8080:
$ sudo lsof -n -i4TCP:8080 | grep LISTEN $
I also checked and my MacOS firewall is turned off.
I don't expect a full solution here, as I'm aware the information I've given is minimal.
What I'm wondering is, how would one go about fixing such a problem?
It seems that the Docker port is unaccessible.
Is there some way of finding out why the port mapping didn't work? Or what ports are being exposed by Docker? Perhaps I'm mapping the wrong internal port?
Or are there any other general suggestions as to what I might be doing wrong here?
-
user9517 over 8 yearsPossible duplicate of What causes the 'Connection Refused' message?
-
-
Gautam about 6 yearsNote - make sure you use the same port in both docker and published fields. Otherwise some links in the ghost site won't work such as home since they are bound to the docker port.