无法连接到通过docker-compose创建的MySQL docker容器(Can't connect to MySQL docker container created via docker-compose)
我想开始使用docker并使用nginx容器,PHP-FPM容器和MySQL容器创建一个简单的容器环境。
虽然nginx和PHP-FPM容器之间的链接运行良好,但我似乎无法将PHP应用程序服务器与数据库服务器链接。
我使用docker-compose来最小化手动终端工作。 我的docker-compose.yml看起来像这样:
web: image: tutorial/nginx ports: - "8080:80" volumes: - ./src:/var/www - ./src/vhost.conf:/etc/nginx/sites-enabled/vhost.conf links: - php php: image: nmcteam/php56 volumes: - ./src/php-fpm.conf:/etc/php5/fpm/php-fpm.conf - ./src:/var/www links: - db db: image: sameersbn/mysql volumes: - /var/lib/mysql environment: - DB_NAME=demoDb - DB_USER=demoUser - DB_PASS=demoPass
我尝试使用以下语句连接到DB:
$db = new \PDO('mysql:host=db;dbname=demoName', 'demoUser', 'demoPass');
MySQL容器本身正在工作,因为我可以连接到容器bash并使用MySQL CLI:
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | demoDb | | mysql | | performance_schema | +--------------------+
我只是得到一个500错误,并找不到为什么这不起作用的原因。 任何对我可能错过的帮助或建议都不胜感激。
I want to get started with docker and created a simple container environment with an nginx container, a PHP-FPM container and a MySQL container.
While the link between the nginx and PHP-FPM container works well I can't seem to link the PHP application server with the database server.
I use docker-compose to minimize the manual terminal work. My docker-compose.yml looks like this:
web: image: tutorial/nginx ports: - "8080:80" volumes: - ./src:/var/www - ./src/vhost.conf:/etc/nginx/sites-enabled/vhost.conf links: - php php: image: nmcteam/php56 volumes: - ./src/php-fpm.conf:/etc/php5/fpm/php-fpm.conf - ./src:/var/www links: - db db: image: sameersbn/mysql volumes: - /var/lib/mysql environment: - DB_NAME=demoDb - DB_USER=demoUser - DB_PASS=demoPass
While I try to connect to the DB with the following statement:
$db = new \PDO('mysql:host=db;dbname=demoName', 'demoUser', 'demoPass');
The MySQL container itself is working as I can connect to the containers bash and use the MySQL CLI:
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | demoDb | | mysql | | performance_schema | +--------------------+
I just get a 500 error and can't find a reason why this wouldn't work. Any help or suggestion of what I might have missed is more than appreciated.
原文:https://stackoverflow.com/questions/37463543
满意答案
缺少分隔符:
preg_match("/^([0-9]{5}|[0-9]{5}\-[0-9]{4})$/", $zip);
Missing delimiters:
preg_match("/^([0-9]{5}|[0-9]{5}\-[0-9]{4})$/", $zip);
相关问答
更多PHP is_numeric或preg_match 0-9验证(PHP is_numeric or preg_match 0-9 validation)
PHP preg_match()PCRE逻辑问题?(PHP preg_match() PCRE logic issue?)
php:preg_match因特殊字符模式而失败(php: preg_match failed with special character pattern)
使用preg_match php [关闭]将数据输入到单独的索引数组中(Inputting data into separate index array using preg_match php [closed])
preg_match需要帮助5 [关闭](preg_match assistance needed 5 [closed])
在PHP中遇到preg_match()问题[关闭](Having an issue with preg_match() in PHP [closed])
PHP - preg_match解释[关闭](PHP - preg_match explanation [closed])
为什么PHP preg_match返回空?(Why is the PHP preg_match returning empty? [closed])
PHP复杂的preg_match(PHP Complicated preg_match)
用于“&$”的PHP中的preg_match(preg_match in PHP for “&$”)
相关文章
更多Docker 容器创建并运行MySQL
揭开Docker神秘的面纱-传智播客Docker视频教程
MySQL最佳实践
my php & mysql FAQ
mysql问题
shell操作mysql初步
MapReduce直接连接MySQL获取数据
MySQL 5.6 my.cnf 配置文件详解
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!