There is my docker-compose.yml
version: '2'
services:
web:
image: nginx:latest
ports:
- "8018:80"
volumes:
- ./code:/code
- ./site.conf:/etc/nginx/conf.d/default.conf
- /private/var/log/nginx:/var/log/nginx
- /private/var/run/php7-fpm.sock:/var/run/php7-fpm.sock
networks:
- code-network
php:
image: php:fpm
volumes:
- ./code:/code
- ./php-fpm.conf:/usr/local/etc/php-fpm.conf
- ./www.conf:/usr/local/etc/php-fpm.d/www.conf
- /private/var/run/php7-fpm.sock:/var/run/php7-fpm.sock
networks:
- code-network
networks:
code-network:
driver: bridge
And in the site.conf I write like this fastcgi_pass unix:/var/run/php7-fpm.sock;
I also change the listen address to listen = /var/run/php7-fpm.sock
in www.conf.
And in my MAC, there is a file named php7-fpm.sock in folder /private/var/run with mode 666
After I ran docker-compose up -d
, the containers was running success.But when I visited http://localhost:8018, it returned 502. After I checked the nginx error log, I found out this
2017/11/01 13:08:39 [error] 6#6: *1 connect() to unix:/var/run/php7-fpm.sock failed (111: Connection refused) while connecting to upstream, client: 172.18.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php7-fpm.sock:", host: "localhost:8018"
Btw, before I tried using unix socket mode. I succeed in visiting http://localhost:8018 with tcp/ip mode.