Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker: Internal Ports

I'm new to docker and wondering why so many examples of docker-compose map ports from internal to external instead of just keeping them the same. For example, one postgres example I saw mapped 4612:5432.

Is there a reason people don't just keep it 5432:5432?

like image 400
aroooo Avatar asked Sep 10 '26 08:09

aroooo


2 Answers

There may be different reasons not to map to same port on host: doing this allows to have multiple Postgres running on separate ports and tweak them in case for some reason you want different ports in DEV/PROD.

like image 109
sashimi Avatar answered Sep 12 '26 23:09

sashimi


For local dev env, except for port conflicting issues, there is no other reason. Unlike exposing ports to internet, there is no security reasons for container port mapping and exposing.

like image 40
HelloThere Avatar answered Sep 13 '26 01:09

HelloThere