From my understanding of docker compose / fig, creating a link between two services/images is one main reason if you do not want to exposes ports to others.
like here db does not expose any ports and is only linked:
web:
  build: .
  links:
   - db
  ports:
   - "8000:8000"   
db:
  image: postgres
Does web thinks db runs on its localhost? Would i connect from a script/program in web to localhost:5432 (standard port from postgresql) to get a database connection?
And if this is correct, how can you change port 5432 to 6432, without exposing? would i just run postgresql on a different port?
Update:
useful links after some input: