ubuntu 18.04 server ufw is not blocking even after configuring DOCKER_OPTS="iptables=false"
In case you don't want to expose your Postgresql to the internet you can map to only localhost in docker-compose.yml
db: image: postgres ports: - '127.0.0.1:5432:5432'