title: Multiple php-fpm containers behind nginx
body: <p>I want to "dockerize" three php based web apps behind nginx as proxy/frontend (also docker, <a href="https://hub.docker.com/_/nginx/" rel="noreferrer">official container</a>): own app, piwik (<a href="https://hub.docker.com/_/piwik/" rel="noreferrer">official php-fpm docker container</a>) and nextcloud (<a href="https://hub.docker.com/_/nextcloud/" rel="noreferrer">official php-fpm docker container</a>)</p>
  
  <p>It works fine with one php-fpm container but not with two or more (/var/www/html is used in at least two php-fpm containers: nextcloud, piwik). The db container is omitted for simplification.</p>
  
  <p>docker-compose.yml:</p>
  
  <pre><code>version: '2'
  
  volumes:
      nextcloud_data:
  
  services:
    web:
      image: nginx:stable
      ports:
        - "80:80"
      volumes:
        - ./conf.d:/etc/nginx/conf.d:ro
      volumes_from:
        - nextcloud
        - piwik # (a)
      links:
        - nextcloud
        - piwik # (a)
      restart: always
    nextcloud:
      image: nextcloud:11.0-fpm
      volumes:
        - nextcloud_data:/var/www/html
      restart: always
    piwik:
      image: piwik:fpm
      restart: always
  </code></pre>
  
  <p>nginx-Config <code>conf.d/piwik.conf</code> - inspired by <a href="https://github.com/indiehosters/piwik/blob/master/nginx.conf" rel="noreferrer">Indiehosters</a>:</p>
  
  <pre><code>upstream php-piwik {
      server piwik:9000;
  }
  
  server {
      index index.php index.html;
      server_name piwik.example.org;
      error_log  /var/log/nginx/error.log;
      access_log /var/log/nginx/access.log;
      root /var/www/html;
  
      location / {
          try_files $uri $uri/ =404;
      }
  
      error_page 404 /404.html;
      error_page 500 502 503 504 /50x.html;
      location = /50x.html {
          root /usr/share/nginx/html;
      }
  
      location = /favicon.ico {
          log_not_found off;
          access_log off;
      }
  
      location ~ \.php$ {
          fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
          fastcgi_param  SERVER_SOFTWARE    nginx;
          fastcgi_param  QUERY_STRING       $query_string;
          fastcgi_param  REQUEST_METHOD     $request_method;
          fastcgi_param  CONTENT_TYPE       $content_type;
          fastcgi_param  CONTENT_LENGTH     $content_length;
          fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
          fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
          fastcgi_param  REQUEST_URI        $request_uri;
          fastcgi_param  DOCUMENT_URI       $document_uri;
          fastcgi_param  DOCUMENT_ROOT      $document_root;
          fastcgi_param  SERVER_PROTOCOL    $server_protocol;
          fastcgi_param  REMOTE_ADDR        $remote_addr;
          fastcgi_param  REMOTE_PORT        $remote_port;
          fastcgi_param  SERVER_ADDR        $server_addr;
          fastcgi_param  SERVER_PORT        $server_port;
          fastcgi_param  SERVER_NAME        $server_name;
          fastcgi_intercept_errors on;
          fastcgi_pass php-piwik;
      }
  }
  </code></pre>
  
  <p>Config for nextcloud is similar (nextcloud.example.org).</p>
  
  <p>Piwik works fine with this setting (nextcloud is broken, <code>/var/www/html</code> in web container contains piwik stuff). When i comment out the (a) marked lines and disable piwik.conf nextcloud works fine but piwik is broken (<code>/var/www/html</code> contains nextcloud stuff). My problem is that they share the same path (<code>/var/www/html</code>). How can i avoid this with official images?</p>