小編給大家分享一下如何解決Laravel使用Windows docker運行php容器及mysql容器時連不起數據庫問題,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
Laravel 項目 使用 Windows docker 運行php 容器 及 mysql 容器時, 在windows git bash 執行 php artisan migrate 發現找不到數據庫。
報錯信息:
Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: 未知 (SQL: select * from ***) at E:\project\vendor\laravel\framework\src\Illuminate\Database\Connection.php:669 665| // If an exception occurs when attempting to run a query, we'll format the error 666| // message to include the bindings with SQL, which will make this exception a 667| // lot more helpful to the developer instead of just the database's errors. 668| catch (Exception $e) { > 669| throw new QueryException( 670| $query, $this->prepareBindings($bindings), $e 671| ); 672| } 673| Exception trace: 1 Doctrine\DBAL\Driver\PDOException::("SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: 知 ") E:\project\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php:31 2 PDOException::("PDO::__construct(): php_network_getaddresses: getaddrinfo failed: 知 ") E:\project\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php:27 Please use the argument -v to see more details.
windows 下執行 php artisan migrate 時連不到容器里的mysql
重新寫一個shell 命令封裝一下 php artisan 命令, 進行容器后執行php artisan 如下:
phpartisan 文件內容
#!/usr/bin/env sh # 進入容器 執行相應php artisan命令 docker exec -i 容器名稱 sh -c "cd /項目的容器路徑 && php artisan $*"
執行 php artisan *
命令 換成 phpartisan *
即可
看完了這篇文章,相信你對“如何解決Laravel使用Windows docker運行php容器及mysql容器時連不起數據庫問題”有了一定的了解,如果想了解更多相關知識,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。