I am playing around with Docker for my local development environment. My setup for now is 5 containers (1 HaProxy + 2 NGINX + 2 PHP7-FPM).
The proxy container is used to direct the request based on the url, so if I enter http://project1.dev it will proxy the request to the project1-nginx that uses project1-php for evaluating php. The setup is similar for http://project2.dev.
Now, I am trying to wrap my head around the ports of the two php containers. The default fpm port is 9000, so both php containers cannot run on this. I am assuming the way to go here is to let both containers export port 9000 but make them 9000 and 9001 on the host?
Something along these lines in my compose file.
project_1_php:
ports:
- "9000:9000"
project_2_php:
ports:
- "9001:9000"
Run Code Online (Sandbox Code Playgroud)
So, everything boots up fine, and project 1 is working, but project 2 gives me a 502. Nginx error log says
2016/01/26 14:37:05 [error] 6#6: *1 connect() failed (111: Connection refused)
while connecting to upstream, client: 172.17.0.9, server: code.dev,
request: "GET / HTTP/1.1", upstream: "fastcgi://172.17.0.4:9001"
Run Code Online (Sandbox Code Playgroud)
对于那些看起来像我一样为不同项目同时运行多个 NGINX 和 PHP-FPM 容器的人,找到了这个 SO 线程,遇到了这个:
https://github.com/docker-library/php/issues/479
在 php-fpm Dockerfile 中:
FROM php:7.2-fpm
RUN sed -i 's/9000/3001/' /usr/local/etc/php-fpm.d/zz-docker.conf
Run Code Online (Sandbox Code Playgroud)
然后在您的docker-compose.yaml文件中,您可以将 Nginx 指向该 PHP-FPM 实例的特定端口。
与 php-fpm7 有类似的问题,正如 @Mjh 在评论中提到的,默认情况下 fpm 监听 127.0.0.1:9000,
所以你应该用 0.0.0.0:9000 替换它,
我在那里找到了一个解决方案:githib:matriphe/docker-alpine-nginx
所以你可以添加到你的 fpm 容器 Dockerfile :
RUN sed -i "s|;*listen\s*=\s*127.0.0.1:9000|listen = 9000|g" /etc/php7/php-fpm.conf
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5033 次 |
| 最近记录: |