溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

如何解決Laravel使用Windows docker運行php容器及mysql容器時連不起數據庫問題

發布時間:2021-03-20 09:12:34 來源:億速云 閱讀:320 作者:小新 欄目:編程語言

小編給大家分享一下如何解決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容器時連不起數據庫問題”有了一定的了解,如果想了解更多相關知識,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女