使用Docker在window10下搭建SWOFT开发环境,mysql连接错误
使用Docker在window10下搭建SWOFT开发环境,mysql连接错误
{
"code": 0,
"error": "(Swoft\\Db\\Exception\\DbException) Pool error is Create connection error(Dsn(mysql:dbname=test;host=127.0.0.1:13306) can not to connected!) file(/var/www/swoft/vendor/swoft/db/src/Connector/MySqlConnector.php) line (43) file=/var/www/swoft/vendor/swoft/connection-pool/src/AbstractPool.php line=250",
"file": "At /var/www/swoft/vendor/swoft/db/src/DB.php line 81",
"trace": "#0 /var/www/swoft/vendor/swoft/db/src/Query/Builder.php(3324): Swoft\\Db\\DB::connection('db.pool')
#1 /var/www/swoft/vendor/swoft/db/src/Query/Builder.php(2437): Swoft\\Db\\Query\\Builder->getConnection()
#2 /var/www/swoft/app/Http/Controller/OrderController.php(35): Swoft\\Db\\Query\\Builder->cursor()
#3 /var/www/swoft/vendor/swoft/stdlib/src/Helper/PhpHelper.php(54): App\\Http\\Controller\\OrderController->buy()
#4 /var/www/swoft/vendor/swoft/http-server/src/Middleware/DefaultMiddleware.php(75): Swoft\\Stdlib\\Helper\\PhpHelper::call(Array)
#5 /var/www/swoft/vendor/swoft/http-server/src/RequestHandler.php(73): Swoft\\Http\\Server\\Middleware\\DefaultMiddleware->process(Object(Swoft\\Http\\Message\\Request), Object(Swoft\\Http\\Server\\RequestHandler))
#6 /var/www/swoft/vendor/swoft/http-server/src/Middleware/ValidatorMiddleware.php(50): Swoft\\Http\\Server\\RequestHandler->handle(Object(Swoft\\Http\\Message\\Request))
#7 /var/www/swoft/vendor/swoft/http-server/src/RequestHandler.php(73): Swoft\\Http\\Server\\Middleware\\ValidatorMiddleware->process(Object(Swoft\\Http\\Message\\Request), Object(Swoft\\Http\\Server\\RequestHandler))
#8 /var/www/swoft/vendor/swoft/http-server/src/Middleware/UserMiddleware.php(54): Swoft\\Http\\Server\\RequestHandler->handle(Object(Swoft\\Http\\Message\\Request))
#9 /var/www/swoft/vendor/swoft/http-server/src/RequestHandler.php(73): Swoft\\Http\\Server\\Middleware\\UserMiddleware->process(Object(Swoft\\Http\\Message\\Request), Object(Swoft\\Http\\Server\\RequestHandler))
#10 /var/www/swoft/vendor/swoft/view/src/Middleware/ViewMiddleware.php(41): Swoft\\Http\\Server\\RequestHandler->handle(Object(Swoft\\Http\\Message\\Request))
#11 /var/www/swoft/vendor/swoft/http-server/src/RequestHandler.php(73): Swoft\\View\\Middleware\\ViewMiddleware->process(Object(Swoft\\Http\\Message\\Request), Object(Swoft\\Http\\Server\\RequestHandler))
#12 /var/www/swoft/app/Http/Middleware/FavIconMiddleware.php(45): Swoft\\Http\\Server\\RequestHandler->handle(Object(Swoft\\Http\\Message\\Request))
#13 /var/www/swoft/vendor/swoft/http-server/src/RequestHandler.php(73): App\\Http\\Middleware\\FavIconMiddleware->process(Object(Swoft\\Http\\Message\\Request), Object(Swoft\\Http\\Server\\RequestHandler))
#14 /var/www/swoft/vendor/swoft/http-server/src/HttpDispatcher.php(80): Swoft\\Http\\Server\\RequestHandler->handle(Object(Swoft\\Http\\Message\\Request))
#15 /var/www/swoft/vendor/swoft/http-server/src/Swoole/RequestListener.php(42): Swoft\\Http\\Server\\HttpDispatcher->dispatch(Object(Swoft\\Http\\Message\\Request), Object(Swoft\\Http\\Message\\Response))
#16 {main}"
}
尝试过检查mysql端口及配置,发现mysql在docker容器里运行正常。但是swoft程序无法正常连接到mysql。请问是不是docker容器间请求服务哪里设置不当的原因?Swoft的DB配置如下:
'db'=> [
'class' => Database::class,
'dsn' => 'mysql:dbname=test;host=127.0.0.1:13306',
'username' => 'root',
'password' => '123456',
'prefix' => 'vc_',
'charset' => 'utf8',
],
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的 mysql 和 swoft 是跑在一个容器里吗?
如果不是,需要先创建桥接网络,让这两个容器处于同一个网段,不然它俩之间就是网络隔离的。