我正在运行两个docker集装箱,使用下面的dockercomposer php脚本:
db: image: cofoundry/mysql environment: - MYSQL_USER=wordpress - MYSQL_PASS=wordpress - MYSQL_DB=wordpress ports: - "3306:3306" privileged: true web: image: cofoundry/nginx-phpfpm volumes: - ../bedrock:/app environment: - DOCROOT=/app/web links: - db ports: - "80:80" privileged: true
但是我找不到任何地方,我怎么能为不同的网站运行多个nginx-phpfpm web和mysql容器,比如web_1 – db_1,web_2 – db_2等。
另外我更改了/ etc / hosts文件以使用boot2docker ip列出所需的所有域,但是如何为它们运行容器? 我不能在相同的端口80和3306上运行容器。
请指教,谢谢!
想象一下networking端口是系统中某个服务的地址。 那么,如果多个服务具有相同的地址,哪一个会收到“邮件”呢? :)事情是只有一个进程可以绑定到某个networking端口。 要解决你的nginx容器问题,你必须configuration一些前端代理(如haproxy)。 您需要将其绑定到:80端口以接受所有传入的连接。 之后,在haproxy.cfg中定义了acls和后端。 对于expample: acl web1 hdr_beg(Host) www.web1.com acl web2 hdr_beg(Host) www.some_other_web.com .... use_backend web1_backend if web1 use_backend web2_backend if web2 .... backend web1_backend ... server web1_server localhost:<random port of nginx container> backend web2_backend ... server web2_server localhost:<other random port of nginx container>
所以,当连接到80端口,haproxyparsing主机头和代理连接匹配的后端。
使用MySQL,您可以为每个实例定义不同的绑定端口,并configuration您的php应用程序来build立连接到所需的端口。 例如: web_1 would use db_1 (port 3306) web_2 would use db_2 (port 3307)等