How to connect to DB in another container with PDO from inside docker container with PHP. Note that the host name is just the container name with the DB
user and password follow docker-compose.yml.
PDO part
$db = new PDO('mysql:host=docker-practice_mysql_1;dbname=restaurant','root','pass');
Container list (terminal)
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
docker-practice_mysql_1
Recommended Posts