title: php-fpm & nginx in separated docker container, can not execute .php file
body: <p>I'd like to setup an completely LNMP environment with docker on a machine. But there is something wrong with separated php-fpm &amp; nginx container.</p>
  
  <p>What I'v done is :</p>
  
  <ol>
  <li><p>pull images from docker.io :</p>
  
  <p>docker pull php:7.1-fpm</p>
  
  <p>docker pull nginx</p></li>
  <li><p>run with image :</p>
  
  <p>docker run -d --name php-fpm -v /data/Docker/php-fpm/configs/:/usr/local/etc/php-fpm.d -v /data/Docker/nginx/html:/var/www/html php:7.1-fpm</p>
  
  <p>docker run -d --name nginx -v /data/Docker/nginx/configs/:/etc/nginx -v /data/Docker/nginx/html:/var/www/html -p 80:80 --link php-fpm nginx</p></li>
  </ol>
  
  <p>All directories &amp; files are 755 privileges.</p>
  
  <p>Config files r below :</p>
  
  <p><code>nginx.conf</code></p>
  
  <pre><code>server {
      listen  80  default_server;
      server_name SkyEyeLab;
      root    /var/www/html;
  
      fastcgi_read_timeout 90;
      location ~ \.php {
      fastcgi_pass    php-fpm:9000;
      }
  }
  </code></pre>
  
  <p>And <code>php-fpm.conf</code>(some of important config sections):</p>
  
  <pre><code>listen 0.0.0.0:9000
  listen.allowed_clients = any
  </code></pre>
  
  <p>Then I checked the environment of nginx &amp; php-fpm :</p>
  
  <pre><code>[root@w-Lab01 ~]# docker ps
  CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                         NAMES
  6faf4a4b4f7e        nginx               "nginx -g 'daemon off"   19 minutes ago      Up 19 minutes       0.0.0.0:80-&gt;80/tcp, 443/tcp   nginx
  9a6caff831d3        php:7.1-fpm         "php-fpm"                20 minutes ago      Up 20 minutes       9000/tcp                      php-fpm
  [root@w-Lab01 ~]# docker exec 6faf4a4b4f7e ping -c3 php-fpm
  PING php-fpm (172.17.0.2): 56 data bytes
  64 bytes from 172.17.0.2: icmp_seq=0 ttl=64 time=0.081 ms
  64 bytes from 172.17.0.2: icmp_seq=1 ttl=64 time=0.018 ms
  64 bytes from 172.17.0.2: icmp_seq=2 ttl=64 time=0.041 ms
  --- php-fpm ping statistics ---
  3 packets transmitted, 3 packets received, 0% packet loss
  round-trip min/avg/max/stddev = 0.018/0.047/0.081/0.026 ms
  [root@w-Lab01 ~]# docker exec 9a6caff831d3 ss -apn
  Netid  State      Recv-Q Send-Q     Local Address:Port       Peer Address:Port 
  tcp    LISTEN     0      128                    *:9000                  *:*      users:(("php-fpm",pid=1,fd=7))
  </code></pre>
  
  <p>Everything seems fine. Then I create a.php under /data/Docker/nginx/html(which is mouted to nginx's /var/www/html directory) with following content :</p>
  
  <pre><code>&lt;?php
  phpinfo();
  ?&gt;
  </code></pre>
  
  <p>Then access <a href="http://localhost:80/a.php" rel="nofollow">http://localhost:80/a.php</a> in web browser.
  But I only got an empty page, I checked the access.log of nginx :</p>
  
  <pre><code>[root@w-Lab01 ~]# docker logs 6faf4a4b4f7e
  220.181.171.120 - - [11/Oct/2016:10:25:11 +0000] "GET /a.php HTTP/1.1" 200 31 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0"
  220.181.171.120 - - [11/Oct/2016:10:25:12 +0000] "GET /a.php HTTP/1.1" 200 31 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0"
  220.181.171.120 - - [11/Oct/2016:10:31:58 +0000] "GET /a.php HTTP/1.1" 200 31 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0"
  220.181.171.120 - - [11/Oct/2016:10:31:59 +0000] "GET /a.php HTTP/1.1" 200 31 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0"
  </code></pre>
  
  <p>It seems <code>a.php</code> is correctly parsed &amp; executed. But why I can not see phpinfo() result in web browser ?</p>