Docker中的HHVM和主机上的MySQL(外部)

时间:2015-04-04 22:42:07

标签: mysql docker hhvm

我使用此配置在cPanel服务器上的Docker中设置HHVM:

http://wiki.mikejung.biz/HHVM

部分 - “如何在cPanel上的Ubuntu泊坞窗容器中运行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>

我检查它是否适用于卷曲:

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服务器有权使用任何远程连接。我想在服务器上使用“localhost”到MySQL服务器。

MySQL运行于:

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

如何将HHVM连接到Docker之外的MySQL?

1 个答案:

答案 0 :(得分:0)

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

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。