DEV Community

loading...
Cover image for Laravel Tinker - SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No address associated with hostname

Laravel Tinker - SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No address associated with hostname

boadusamuel profile image samuel boadu ・2 min read

Read some good reviews on laravel tinker, a phpstorm plugin which I wanted to try out. I installed the plugin on my phpstorm editor and was ready to start tinkering. Was using Laradock which I had configuration for apache2, mysql, workspace and phpmyadmin. All was running well until I decided to experiment with laravel tinker.

This was the setup for mysql database connection in the .env file.
Alt Text

Laravel tinker could not resolve the host name -

Illuminate\Database\QueryException with message 'SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No address associated with hostname.

After long hours of reading and searching online for a solution I couldn't get the help I needed. I later had suggestion from a senior colleague to use the IP adrress of mysql docker container. I did try and this time around the error changed to

Illuminate\Database\QueryException with message 'SQLSTATE[HY000] [2002] Connection timed out

Making progress at least. I then inspected the mysql docker container networks by using the command :
docker inspect [container id]

Had a long list of information on the container but the focus was on the Networks properties of the NetworkSettings.

Alt Text

I then changed the IPAddress to the Gateway which is equally an IP but directs traffic locally. Lo and Behold Laravel tinker was up and running.....
Alt Text

Hope this article helps someone who might find him or herself in similar situation. Comments and corrections are welcome as we all learn by building each other up.

Discussion (0)

Forem Open with the Forem app