我使用以下配置在 cPanel 服务器上的 Docker 内设置了 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/