Connecting php-fpm and mysql containers together


I’m still a rookie in Docker. Currently, I am running php-fpm and mysql in Docker Containers. Before using Docker, my php code connects to mysql database via localhost usually, but this isn’t going to work with Containers. As each Container has its own IP, I need to change the host setting to the mysql container’s IP.

As a test, I have tried and could connect to the mysql container with manual IP assigning in the PHP code, but obviously this is not practical. The IP will change, etc. How do we usually do something like this in Docker? I am not sure how to connect the puzzle pieces together yet in this case.

Thank you.