This week I was trying to run an image that always worked using ports localhost:8500 or localhost:8501 , but suddenly it stopped to work in localhost and just works in the internal container IP like 172.17.0.2:8500 or 172.17.0.2:8501.
If I try to use localhost or 0.0.0.0 again I get connection refused, but the ports are listening normally using the command sudo lsof -i -P -n | grep 8500 or sudo lsof -i -P -n | grep 8501
Docker service status also looks normal.
telnet command for 172.17.0.2 works but for localhost I have my connection refused.
I already tried to restart docker and reload daemon , even tried to reinstall docker , but the problem persists.
I really wanted to use localhost again and really wanted to find a solution without need to reboot, since I am working with remote access in the server of my company .
Without seeing how you create the container it is hard to help. If you want a container to accept request on the localhost of the host operating system you need to forward a port. Make sure you never use the “latest” tag of any image, since the image can change and you can pull a different version which works differently The host can change too. It is very important to know how you installed Docker since there are many kind of Docker.
Install from a snap repository
Installed from the Linux distribution’s repository
Installed from the repository of Docker, Inc
Installed on a not supported operating system from a wrong repository or by downloading a binary
Using Docker Desktop
Docker Desktop for Windows
Docker Desktop for Linux
Docker DEsktop for Mac
Using an other container engine and adding “docker” as an alias.