Connect RDS (PostgreSQL) from Docker container

Step 1: Run the postgres docker container

$ docker run -it --rm --network=host postgres:11.16 bash
root@a018fe70d745:/# apt update && apt install telnet -y

Step 2: Check if postgres is connected by using telnet command

For example the endpoint of the RDS:

root@a018fe70d745:/# telnet 5432
Connected to
Escape character is '^]'.

Step 3: Connect using the psql command

The command: psql -h -p 5432 -U <username> -d <dbname> -W

root@a018fe70d745:/# psql -h -p 5432 -U test -d db_test -W
psql (11.16 (Debian 11.16-1.pgdg90+1))
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.