No access to AWS RDS from AWS ECS Docker Container

I have a spring boot app packaged in docker image(based on openjdk:8-jdk-alpine). As a datasource i want to use RDS. I configured postgresql RDS instance and i have access to it from my local box.
However when i deploy app to ECS i have the following issue: from EC2 instance i can access 5432 port:

nmap -Pn -p 5432 172.31.2.43
...
PORT     STATE SERVICE
5432/tcp open  postgresql

But from the docker container started on this instance i cannot access RDS:

  • Point different domains to different Docker containers on a single EC2 instance?
  • Running Docker container randomly disappears on AWS EC2 Ubuntu
  • AWS EB with Docker, Node and Nginx Config Issues
  • How to send node.js logs to Cloudwatch Logs from Elastic Beanstalk Docker application?
  • How to Access AWS EC2 docker tomcat instance running inside jenkins docker instance from my local browser
  • Using pm2 Inside of an Auto-Scaling Environment
  • PORT     STATE  SERVICE
    5432/tcp closed postgresql
    

    Both RDS and EC2 instance are within same VPC. Security group for RDS allow incoming connections from all ip addresses. I tried to start docker container with –net=host and it didn’t help. RDS endpoint seems to be not visible from container

    Could anyone suggest what can be adjusted/changed?

  • PDO connection error when running PHINX migration on a Docker Container
  • Cannot stop or kill Docker image
  • How to build docker source code after modifying it?
  • How to connect mysql in a rails app with docker?
  • NPM install via git+https//x-oauth-basic within Docker container fails
  • What is the difference between docker and docker-compose
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.