您好,欢迎访问一九零五行业门户网

解决Laravel使用Windows docker运行php容器及mysql容器时,连不起数据库问题

下面由laravel教程栏目给大家介绍解决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视频教程
以上就是解决laravel使用windows docker运行php容器及mysql容器时,连不起数据库问题的详细内容。
其它类似信息

推荐信息