Cannot connect via PHP to docker mysql Cannot connect via PHP to docker mysql docker docker

Cannot connect via PHP to docker mysql


I think it's the way it's trying to find the container via the host name 'db', I've found that on the machine running docker, it doesn't seem to pick up the names of the guest containers (could be some DNS config you could change) but the way I've worked round it is to find the IP address of the MySQL container. I have docker_db_1 as the container name for MySQL, so I run (assuming *nix)

docker inspect docker_db_1 | grep IPAddress

Which in my case gives me

    "SecondaryIPAddresses": null,    "IPAddress": "",            "IPAddress": "172.18.0.2",

And I use this IP address (172.18.0.2) to connect to rather than db.