Can't connect to PostgreSQL Docker container on AWS EC2 instance
Docker newbie here.
I am trying to create a Docker container for PostgreSQL on an AWS EC2 instance.
First, I use a data container to achieve persistence . Here is the command I used to create the data volume container for my PostgreSQL database:
docker create -v /var/lib/postgresql/data --name postgres9.3.6-data busybox
Then I run the following command to create the PostgreSQL container:
docker run --name postgres9.3.6 \
-p 5432:5432 \
-e POSTGRES_PASSWORD=password \
-e POSTGRES_USER=root \
-e POSTGRES_DB=db_name \
-d --volumes-from postgres9.3.6-data postgres:9.3.6
I ran this in my local environment and then tried to connect to it via the PostgreSQL desktop client and it worked. I was able to connect to the db_name which is stored in the local PostgreSQL docker container.
After that, I snuck into one of my EC2 instances on AWS. And the same stream followed, which I described above. Then I went back to the PostgreSQL desktop client and tried to connect to it. But I got the following error message:
The connection was rejected. Make sure the hostname and port are correct and that the postmaster is accepting TCP / IP connections.
What am I missing here?
Edit
I already checked and set listen_addresses in postgresql.conf file to
listen_addresses='*'
and added the following line to pg_hba.conf file:
host all all 0.0.0.0/0 md5
source to share