To connect from outside the container, use your host machine's IP address.
Here's an example: If your host machine (e.g., host-docker-01) has the IP 10.1.0.101, connect like this:
host-docker-01
10.1.0.101
psql -h 10.1.0.101 -p 5432 -U username -d dbname