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: rds-database.abcdefghi.us-east-1.rds.amazonaws.com

root@a018fe70d745:/# telnet rds-database.abcdefghi.us-east-1.rds.amazonaws.com 5432
Connected to rds-database.abcdefghi.us-east-1.rds.amazonaws.com.
Escape character is '^]'.
^]

Step 3: Connect using the psql command

The command: psql -h rds-database.abcdefghi.us-east-1.rds.amazonaws.com -p 5432 -U <username> -d <dbname> -W

root@a018fe70d745:/# psql -h rds-database.abcdefghi.us-east-1.rds.amazonaws.com -p 5432 -U test -d db_test -W
Password: 
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.

db_test=>