Node.js Application and MongoDB in Docker on AWS: Connection Issue without Opening DB Port in Inbound Rules

I’m running a Node.js application and MongoDB, both in Docker containers on an AWS EC2 instance. The application connects to the database only if I open the inbound rule for the MongoDB port (27017), which poses a security risk. How can I securely connect my application to the MongoDB container without exposing the database port in the security group? I’ve tried using Docker networks, but it hasn’t resolved the issue. Any advice on best practices or configurations would be appreciated.