After a while I forget which container sits behind which port on the host. Instead of scrolling through docker ps output, I ask the container itself.
docker port mycontainer
docker port mycontainer 80
Without a port the command lists every published mapping, one per line, such as 80/tcp -> 0.0.0.0:8080. With a container port as an argument it prints only that mapping. When you let Docker pick a random host port with -p 80, this is the quickest way to find out which one it took.
For Compose the same idea is docker compose port db 5432, which asks for the mapping of a service instead of a container name.
Look at the address part. 0.0.0.0 means the port is reachable on every interface of the host. If the service should only be used locally, publish it as 127.0.0.1:8080:80 and run the command again to confirm it changed.
The caveat is scope: docker port only knows ports that were published with -p or -P. A port that is merely declared with EXPOSE is documentation and does not appear. Containers on --network host publish nothing either, so the output is empty even though the service is listening.
Further reading: Port publishing and mapping