laravel-tinker: Database access results in php_network_getaddresses error
Bug description Database access does not work resulting in the following error:
Illuminate\Database\QueryException with message 'SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for mysql failed: Name or service not known (SQL: select * from `orders` where `orders`.`id` = 2 limit 1)'
To Reproduce
Run any code that requires access to the database. If the code does not require access to the database, it seems to work fine.
I can also confirm that my application has access to the database and running tinker locally with sail artisan tinker also works fine with the database.
The following is the code that I used:
//Tinker away!
use App\Models\Order;
Order::find(2);
Screenshots

Environment (please complete the following information):
- IDE & Version: IntelliJ IDEA 2022.1.2 (Ultimate Edition)
- PHP Version: 8.1.7
- OS: Windows 10
- Laravel Tinker plugin version: 2.3.4
- Interpreter Type: Docker (using Laravel Sail)
- Laravel Version: 8.83
- Tinker version: 2.7.2
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 20 (9 by maintainers)
@quantumwebco Your interpreter is “Docker”, not “Docer compose”.
If you want to keep on using docker, the container needt all the settings it needs to reach the mysql container.
@quantumwebco Everyone has to learn some time, and once you get the hang of docker, it’s going to be great!
Solution was to use
docker-compose.ymland setting it asdocker-compose exec:I then faced the following issue which, I believe, can be solved by upgrading to the latest PHPStorm version: https://github.com/Roboroads/laravel-tinker/issues/14