Recently, i've created a container for my project, and also tried to assign its port (9002, specified in Dockerfile) to host port by adding:
-p 9003:9002 (i attached it to port 9003 of the host )
in "Docker run" when i generated new container. Then i wrote a server program,which is run inside container, to use port 9002, and i'd believed that the data sent out from my container via port 9002 would somehow get out of the host-pc via port 9003.
However, the client program ran on other pc didn't receive anything from port 9003 but 9002 instead. Then i realized that i don't need to assign port precisey at the first place, just assign container-port to whatever host-port i want and i can send data out to any port of my host pc.
So what did i misunderstand here about the assigning command above?
i thought without assigning port, container can't communicate outside its network?