Problem
How to bind a dockerized service to a local socket?
Solution
According to the documentation, the format of --publish
option is: ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort | containerPort
.
Hence, if you want to bind to localhost you could use -p 127.0.0.1:8080:8080
and you're done.
This was tested with this command: docker run -p 127.1.2.3:9080:9080 --rm -it debian
running a netcat
listening on the port 9080.
Bonus
Btw, I guess that you run sshd
in your container according to the option -p 2022:22
. I would like to point this article made by a Docker engineer that worth the reading.
Have fun!