Docker Community Forums

Share and learn in the Docker community.

Docker (Docker compose) always listen in localhost port even if the process of the container is stopped

docker

(Cesarjorgemartinez) #1

Hi,

I have in a host, one container that use two ports, 5050 and 5051 (two instances).
Then, I need to only bind these ports to localhost (127.0.0.1).

container…

  • ports:
    • “127.0.0.1:5050:5050”
    • “127.0.0.1:5051:5051”

Then, I have an alarms to check TCP connection to localhost:
check_tcp -H 127.0.0.1 -p 5050
check_tcp -H 127.0.0.1 -p 5051

When the two instances are UP, then I get an OK.

If I enter in the container, and, for example, kill one one instance (example 5051), and go back to the host and launch the checks (or do ncat -v 127.0.0.1 5050/5051):
check_tcp -H 127.0.0.1 -p 5050
check_tcp -H 127.0.0.1 -p 5051

Then, always get an OK, but the check of 5051 shoud fail, but not.

If I bind the container to all “0.0.0.0”, and change the checks to:
check_tcp -H hostip -p 5050
check_tcp -H hostip -p 5051

And kill the 5051 instance in the container, then the 5051 check is executed with failed state (correct).

It is a bug?

Regards,
Cesar Jorge