Connecting to remote mysql database from apache container

I am learning to use Docker for my work. I created a php apache container to host my website. I can connect to a mysql container from the php container. However, when I try to connect to a remote database (on AWS), it does not work.
The message I get is:
Warning : mysqli::__construct(): (HY000/2002): Connection timed out in /var/www/html/index.php on line 19
Connection failed: Connection timed out

Can anyone tell me how I can connect to a remote mysql database using a container?