Assuming that in your docker-compose.yml
, you have 2 services and named them php
and db
:
<?php
# Assuming you name your differents services like `php`, `db` for example, you can get the IP address with
echo \gethostbyname('php');
echo \gethostbyname('db');