I have AWS ec2 instance that runs docker compose:
version: ‘3.8’
services:
prod-db:
image: postgres:13-alpine
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: mypassword
volumes:
- production_data:/var/lib/postgresql/data
- ./script.sql:/docker-entrypoint-initdb.d/create_script.sql
ports:
- "5432:5432"
volumes:
production_data:
And i want to connect to this postgress from remote machine.
I have ensured that the postgres config allows remote connection with:
docker exec -it prod-db bash
echo "listen_addresses = '*'" >> /var/lib/postgresql/data/postgresql.conf
echo "host all all 0.0.0.0/0 md5" >> /var/lib/postgresql/data/pg_hba.conf
docker compose restart prod-db
However i am still unable to connect to postgress from my local machine.
Local connection from ec2 instance works. And configuration should be correct, so where is the catch?
I am using my public ipv4 address of my ec2 instance for connectiction, so for jdbs it looks like
jdbc:postgresql://<public ipv4 address of my ec2 instance>:5432/<database name>
The database is created by script.sql
, and everything is correctly created.
Why is this happening? Did i forget some postgres config or some aws ec2 config? Afaik the port 5432 should be public on ec2.
4