I am running a docker container by docker run -p 8080:8080. Other computers can visit my server by visiting [my ip]:8080. However, for security reasons, I want only localhost(127.0.0.0) is able to access to my server. I do not want other people to connect to my server. How do I restrict that a docker container only listens the host 127.0.0.1?
You can use:
docker run -p 127.0.0.1:8080:8080 your_image_name
This will map the container's port 8080 to only listen on host's 127.0.0.1 at port 8080.