mysql - Docker 内部的 HHVM 和主机上的 MySQL(外部)

标签 mysql docker hhvm

我使用以下配置在 cPanel 服务器上的 Docker 内设置了 HHVM:

http://wiki.mikejung.biz/HHVM

部分 - “如何在 cPanel 上的 Ubuntu docker 容器中运行 HHVM”

我的 Docker 配置是:

"Name": "/sad_wozniak",
"NetworkSettings": {
    "Bridge": "docker0",
    "Gateway": "172.17.42.1",
    "IPAddress": "172.17.0.13",
    "IPPrefixLen": 16,
    "MacAddress": "02:42:ac:11:00:0d",
    "PortMapping": null,
    "Ports": {
        "9000/tcp": [
            {
                "HostIp": "0.0.0.0",
                "HostPort": "9000"

在域的 VirtualHost 上我添加:

    <IfModule mod_proxy_fcgi.c>
            ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://172.17.0.13:9000/home/username/public_html/
    </IfModule>

我检查它是否适用于curl:

HTTP/1.1 200 OK
Date: Sat, 04 Apr 2015 22:34:52 GMT
Server: Apache
X-Powered-By: HHVM/3.6.1
X-Mod-Pagespeed: 1.9.32.3-4448
Cache-Control: max-age=0, no-cache
Content-Length: 17
Content-Type: text/html; charset=utf-8

但是我收到 MySQL 错误:

Error establishing a database connection

外部 Docker MySQL 服务器有权使用任何远程连接。我想在 MySQL 服务器的服务器上使用“localhost”。

MySQL 运行于:

tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      498        19250361   3206/mysqld

如何将 HHVM 与 Docker 外部的 MySQL 连接?

最佳答案

正如文档所述,您需要将主机地址作为别名添加到容器

http://docs.docker.com/reference/commandline/cli/#adding-entries-to-a-container-hosts-file

Note: Sometimes you need to connect to the Docker host, which means getting the IP address of the host. You can use the following shell commands to simplify this process:

 $ alias hostip="ip route show 0.0.0.0/0 | grep -Eo 'via \S+' | awk '{ print \$2 }'"
 $ docker run  --add-host=docker:$(hostip) --rm -it debian

之后,您应该能够使用容器中的地址 docker:3306 连接到主机 MySQL。

关于mysql - Docker 内部的 HHVM 和主机上的 MySQL(外部),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29452199/

相关文章:

php - 记住我的代码在我的脚本 php 中不起作用

mysql - "where not in (subquery)"对于大表来说非常慢

Azure WebApp容器重启问题

php - 如何在 HHVM 3.3.0 上启用 xdebug?

php - 如何在 HHVM 上向浏览器输出/显示 fatal error

php - 如何在 ubuntu 中安装特定版本的 HHVM

php - 如何合并 SQL 查询

即使已连接,PHP 也无法选择数据库

docker - 如何在卷中挂载单个文件

java - 如何在 Jenkins 管道中获取 Maven 版本