- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我正在使用 Docker 创建一个容器,以在我的 Mac 上测试基于 PHP 和 MySQL 构建的 Web 应用程序。我的 PHP 应用程序是使用用于 MVC 和路由的 Fat-Free 框架构建的。我有两个 Dockerfile,一个用于 MySQL,一个用于 PHP。我已经成功使用测试 Docker 应用程序,所以我相信我的图像安装正确。
错误的主要部分:
Internal Server Error
SQLSTATE[HY000] [2002] No such file or directory
[fatfree/lib/DB/SQL.php:466] PDO->__construct('mysql:host=127.0.0.1;port=3306;dbname=robohome','root','password',array(1002=>'SET NAMES utf8;'))
[fatfree/app/Controllers/Controller.php:24] DB\SQL->__construct('mysql:host=127.0.0.1;port=3306;dbname=robohome','root','password')
注意,如果我使用 127.0.0.1
而不是 localhost
进行连接,我会收到一个稍微不同的错误:SQLSTATE[HY000] [2002] Connection denied
我的 PHP Dockerfile:
FROM php:5.6-apache
RUN docker-php-ext-install mysqli pdo pdo_mysql
RUN a2enmod rewrite
我的 MySQL Dockerfile:
FROM mysql:5.7
ENV MYSQL_ROOT_PASSWORD password
ENV MYSQL_DATABASE robohome
COPY ./schema.sql /docker-entrypoint-initdb.d/
我的 Controller.php
文件,其中错误提到第 24 行:
<?php
namespace Controllers;
class Controller
{
protected $f3;
protected $db;
public function __construct()
{
$f3 = \Base::instance();
$this->f3 = $f3;
$mysqlServerName = $f3->get("MYSQL_SERVERNAME");
$mysqlDatabseName = $f3->get("MYSQL_DBNAME");
//$container = \DI\ContainerBuilder::buildDevContainer(); <-Not used currently
//Below is line 24 referred to in the error
$db = new \DB\SQL(
"mysql:host={$mysqlServerName};port=3306;dbname={$mysqlDatabseName}",
$f3->get("MYSQL_USERNAME"),
$f3->get("MYSQL_PASSWORD")
);
$this->db = $db;
}
那些 MYSQL_*
值是从 .ini
文件中提取的:
MYSQL_SERVERNAME = "localhost" <-This is what I've tried changing to 127.0.0.1
MYSQL_USERNAME = "root"
MYSQL_PASSWORD = "password"
MYSQL_DBNAME = "robohome"
我的 Docker 撰写文件:
version: '2'
services:
web:
build: ./docker/php
ports:
- 80:80
volumes:
- .:/var/www/html/
links:
- db
db:
build: ./docker/mysql
ports:
- 3306
我通过执行 docker-compose up --build -d
来运行它。然后我可以从 docker ps
得到的输出是:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f35066a16586 robohomeweb_mysql "docker-entrypoint.sh" 3 minutes ago Up 2 seconds 0.0.0.0:32777->3306/tcp robohomeweb_mysql_1
86d34eb34583 robohomeweb_php "apache2-foreground" 3 minutes ago Up 2 seconds 0.0.0.0:80->80/tcp robohomeweb_php_1
如果我改为在前台运行,我会得到以下输出:
Building php
Step 1 : FROM php:5.6-apache
---> 8f9b7e57129a
Step 2 : RUN docker-php-ext-install mysqli pdo pdo_mysql
---> Using cache
---> fadd8f9e7207
Step 3 : RUN a2enmod rewrite
---> Using cache
---> 9dfed7fdc60f
Successfully built 9dfed7fdc60f
Building mysql
Step 1 : FROM mysql:5.7
---> eda6a4884645
Step 2 : ENV MYSQL_ROOT_PASSWORD password
---> Using cache
---> 759895ac5772
Step 3 : ENV MYSQL_DATABASE robohome
---> Using cache
---> e926c5ecc088
Step 4 : COPY ./schema.sql /docker-entrypoint-initdb.d/
---> Using cache
---> cf5d00aa8020
Successfully built cf5d00aa8020
Starting robohomeweb_php_1
Starting robohomeweb_mysql_1
Attaching to robohomeweb_mysql_1, robohomeweb_php_1
php_1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.18.0.3. Set the 'ServerName' directive globally to suppress this message
php_1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.18.0.3. Set the 'ServerName' directive globally to suppress this message
php_1 | [Sun Oct 16 20:21:17.944575 2016] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.10 (Debian) PHP/5.6.26 configured -- resuming normal operations
php_1 | [Sun Oct 16 20:21:17.946919 2016] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
mysql_1 | 2016-10-16T20:21:18.036272Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
mysql_1 | 2016-10-16T20:21:18.038330Z 0 [Note] mysqld (mysqld 5.7.16) starting as process 1 ...
mysql_1 | 2016-10-16T20:21:18.043331Z 0 [Note] InnoDB: PUNCH HOLE support available
mysql_1 | 2016-10-16T20:21:18.043603Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
mysql_1 | 2016-10-16T20:21:18.043951Z 0 [Note] InnoDB: Uses event mutexes
mysql_1 | 2016-10-16T20:21:18.044077Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
mysql_1 | 2016-10-16T20:21:18.044260Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
mysql_1 | 2016-10-16T20:21:18.044414Z 0 [Note] InnoDB: Using Linux native AIO
mysql_1 | 2016-10-16T20:21:18.045150Z 0 [Note] InnoDB: Number of pools: 1
mysql_1 | 2016-10-16T20:21:18.045620Z 0 [Note] InnoDB: Using CPU crc32 instructions
mysql_1 | 2016-10-16T20:21:18.047629Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
mysql_1 | 2016-10-16T20:21:18.057705Z 0 [Note] InnoDB: Completed initialization of buffer pool
mysql_1 | 2016-10-16T20:21:18.059988Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
mysql_1 | 2016-10-16T20:21:18.074670Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
mysql_1 | 2016-10-16T20:21:18.101209Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
mysql_1 | 2016-10-16T20:21:18.101433Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
mysql_1 | 2016-10-16T20:21:18.354806Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
mysql_1 | 2016-10-16T20:21:18.356928Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
mysql_1 | 2016-10-16T20:21:18.357158Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
mysql_1 | 2016-10-16T20:21:18.358049Z 0 [Note] InnoDB: Waiting for purge to start
mysql_1 | 2016-10-16T20:21:18.412987Z 0 [Note] InnoDB: 5.7.16 started; log sequence number 12179647
mysql_1 | 2016-10-16T20:21:18.414470Z 0 [Note] Plugin 'FEDERATED' is disabled.
mysql_1 | 2016-10-16T20:21:18.421833Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
mysql_1 | 2016-10-16T20:21:18.424144Z 0 [Note] InnoDB: Buffer pool(s) load completed at 161016 20:21:18
mysql_1 | 2016-10-16T20:21:18.425607Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
mysql_1 | 2016-10-16T20:21:18.427018Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
mysql_1 | 2016-10-16T20:21:18.427581Z 0 [Note] IPv6 is available.
mysql_1 | 2016-10-16T20:21:18.427749Z 0 [Note] - '::' resolves to '::';
mysql_1 | 2016-10-16T20:21:18.428019Z 0 [Note] Server socket created on IP: '::'.
mysql_1 | 2016-10-16T20:21:18.456023Z 0 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
mysql_1 | 2016-10-16T20:21:18.456354Z 0 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
mysql_1 | 2016-10-16T20:21:18.480237Z 0 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
mysql_1 | 2016-10-16T20:21:18.488758Z 0 [Note] Event Scheduler: Loaded 0 events
mysql_1 | 2016-10-16T20:21:18.490880Z 0 [Note] mysqld: ready for connections.
mysql_1 | Version: '5.7.16' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL)
根据我的研究,我尝试使用 localhost
和 127.0.0.1
进行连接,因为它们在技术上的处理方式不同。它也可能与尝试通过套接字而不是 TCP 交谈有关。理想情况下,我想要一个解决方案,我可以将其烘焙到我的 Dockerfiles 中,这样我就不必担心记住命令或我是如何做某事的。
最佳答案
正如评论中有人指出的那样,您提供的 docker-compose 文件与您的问题非常相关。
links
的文档在 docker-compose 文件中说
Containers for the linked service will be reachable at a hostname identical to the alias, or the service name if no alias was specified.
在您的情况下,数据库容器名为 db
,因此从 PHP 容器解析 db
主机应该指向 MySQL 容器。在配置文件中将 localhost
替换为 db
应该允许 PHP 容器连接到 MySQL。
关于php - 使用 Docker 我得到错误 : "SQLSTATE[HY000] [2002] No such file or directory",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40075065/
env file:环境文件: APP_ENV=localAPP_DEBUG=trueAPP_KEY= ...........DB_HOST=srv3.linuxisrael.co.ilDB_D
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我在这里有一个 plpgsql 函数来指示在 ANALYZE 期间是否引发了任何警告: CREATE OR REPLACE FUNCTION analyzeWarning() RETURNS inte
我创建了一个过程,如果输入等于 0,该过程将抛出 SQLException 并显示错误消息“dwa”。 CREATE PROCEDURE enter_the_dragon(test INT) BEGI
我在尝试通过 8443 门户连接到我的服务器时收到此错误: ERROR: Zend_Db_Adapter_Exception: SQLSTATE[HY000] [2002] No such file
在插入投票之前,我需要检查每个用户的声誉数。因此,为了这个目的,我有一个像这样的TRIGGER: CREATE TRIGGER check_reputation BEFORE INSERT ON vo
Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error oraccess violation: 1064 You have
MYSQL 在处理通过别名调用的表的子查询时触发 SQLSTATE[42S02] 错误 “更新 call_log AS c1 INNER JOIN call_log AS c2 ON c1.id =
我在 PostgreSQL (mixbest) 中有一个包含 73018 行的表。我要选择的字段是: sample integer m integer, pciv double prec
我刚刚收到此错误...请帮我解决这个错误! www.sp-power.com Error in file: "/home/sppower6/public_html/app/code/core/Mage
例如,我有产品[香蕉]和产品[橙色],我希望这两个产品在数据库中使用相同的图片。但是,当我尝试添加与第一个产品具有相同图片的第二个产品时,我收到此错误: SQLSTATE[23000]: Integr
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 已关闭 7 年前。 编辑问题以包含 desired behavior, a specific problem
Closed. This question is off-topic。它当前不接受答案。
运行时: DELIMITER $$ CREATE TRIGGER tr_test BEFORE UPDATE ON test FOR EACH ROW BEGIN
我的代码大部分已经运行起来了。我似乎不断地一遍又一遍地犯同样的错误。我认为这是因为我在错误的地方放了逗号,但我不知道。谁能帮我看一下这段代码吗? setAttribute(PDO::ATTR_ERRM
我正在尝试获取我的 yii 应用程序的时间范围。 这是我的模型: public function timeRange($attribute, $params) { $criteria
prepare($sql); foreach($parameters as $name=>$value){ $query->bindValue($name,$value);
我有一个前触发器,它可以防止数据更新到表中。为此,我使用了“SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'This operation is not allo
您好,我在 SQL 查询中遇到错误,无法弄清楚问题出在哪里。这是到目前为止在 Barmar 的帮助下的查询。 $query = "SELECT c.*, count(s.curso_id) as c
我构建了 restful API 及其工作,但是当我尝试将参数传递给链接时,下面显示错误,尽管当我打印参数时结果是正确的! 详细信息 Type: PDOException Code: 42000 Me
我是一名优秀的程序员,十分优秀!