How do I configure default.conf in kubernetes. This docker-compose works locally:
version: '3'
services:
php:
container_name: my_php
build:
context: .
dockerfile: php/Dockerfile
ports:
- 9002:9000
volumes:
- ../:/var/www/some-service
- ./logs/application:/var/www/some-service/var/logs:cached
networks:
- some-service
nginx:
container_name: my_nginx
build:
context: .
dockerfile: nginx/Dockerfile
ports:
- 8080:80
volumes:
- ../:/var/www/some-service
- ./logs/nginx/:/var/log/nginx:cached
networks:
- some-service
db:
image: mysql:5.7
container_name: my_db
environment:
- MYSQL_ROOT_PASSWORD=root
volumes:
- some-service-db:/var/lib/mysql:cached
ports:
- 3311:3306
networks:
- some-service
volumes:
some-service-db:
networks:
some-service:
driver: bridge
The default.conf looks like this:
server {
index index.php
server_name localhost;
root /var/www/some-service/public;
location / {
try_files $uri #rewriteapp;
}
location #rewriteapp {
rewrite ^(.*)$ /index.php/$1 last;
}
location ~ ^/index\.php(/|$) {
fastcgi_pass php:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
error_log /var/log/nginx/some-service-error.log;
access_log /var/log/nginx/some-service-access.log;
}
When I deploy to kubernetes, I get the following error from nginx container:
2018/10/14 22:51:14 [emerg] 1#1: host not found in upstream "php" in /etc/nginx/conf.d/default.conf:15
nginx: [emerg] host not found in upstream "php" in /etc/nginx/conf.d/default.conf:15
I then got rid of the port in fastcgi_pass php:9000; but then got no port in upstream "php". So I added the below to the default.conf:
upstream php {
server php;
}
But now I get the error:
2018/10/14 23:32:23 [emerg] 1#1: upstream "php" may not have port 9000 in /etc/nginx/conf.d/default.conf:15
nginx: [emerg] upstream "php" may not have port 9000 in /etc/nginx/conf.d/default.conf:15
I also changed the port to 9002 but get the same error but for 9002. In my kubernetes deployment yaml, I used the container ports from the docker-compose as the containerPort value. The php and db containers start fine. How do I configure nginx to work correctly in kubernetes with the php container?
Update
I got nginx to not crash by changing the fastcgi_pass php:9000; to fastcgi_pass 127.0.0.1:9002. However, it still seems to not crash if you just have any IP or port. As long as I have both it will not crash.
Update 2: Reply to Matthews comments
This is the deployment yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: some-service-deployment
labels:
app: some-service
spec:
replicas: 1
selector:
matchLabels:
app: some-service
template:
metadata:
labels:
app: some-service
spec:
containers:
- name: php
image: 1111111.dkr.ecr.us-east-1.amazonaws.com/some-service/php:latest
ports:
- containerPort: 9002
- name: nginx
image: 1111111.dkr.ecr.us-east-1.amazonaws.com/some-service/nginx:latest
ports:
- containerPort: 8089
volumeMounts:
- name: config-volume
mountPath: /etc/nginx/conf.d/
- name: db
image: mysql:5.7
ports:
- containerPort: 3311
env:
- name: MYSQL_ROOT_PASSWORD
value: somepassword
volumes:
- name: config-volume
configMap:
name: nginx-conf
I wanted to chime in since I faced the same problem while helping a colleague troubleshooting this issue.
I looked up the kubernetes documentation and container-to-container communications within a pod must pass through localhost, there is no name aliasing like it happens with docker-compose on the desktop.
Here is links and extracts from the kubernetes documentation:
From the page "Cluster Networking" (https://kubernetes.io/docs/concepts/cluster-administration/networking/)
Networking is a central part of Kubernetes, but it can be challenging
to understand exactly how it is expected to work.
There are 4 distinct networking problems to address:
1. Highly-coupled container-to-container communications:
this is solved by Pods and localhost communications.
2. Pod-to-Pod communications: this is the primary focus of this document.
3. Pod-to-Service communications: this is covered by services.
4. External-to-Service communications: this is covered by services.
From the page "Pods", section "Pods networking" (https://kubernetes.io/docs/concepts/workloads/pods/#pod-networking):
Inside a Pod (and only then), the containers that belong to the Pod can
communicate with one another using localhost.
[cut]
Within a Pod, containers share an IP address and port space, and can find
each other via localhost.
Related
I've got a Mezzio application that works perfectly on built-in php server using compoer serve, however, when I try it in docker environment, it gives me following error.
Fatal error: Uncaught Laminas\View\Exception\RuntimeException: Laminas\View\Renderer\PhpRenderer::render: Unable to render template "error::error"; resolver could not resolve to a file in /var/www/portal/vendor/laminas/laminas-view/src/Renderer/PhpRenderer.php:492 Stack trace: #0 /var/www/portal/vendor/mezzio/mezzio-laminasviewrenderer/src/LaminasViewRenderer.php(232): Laminas\View\Renderer\PhpRenderer->render(NULL) #1 /var/www/portal/vendor/mezzio/mezzio-laminasviewrenderer/src/LaminasViewRenderer.php(221): Mezzio\LaminasView\LaminasViewRenderer->renderModel(Object(Laminas\View\Model\ViewModel), Object(Laminas\View\Renderer\PhpRenderer), Object(Laminas\View\Model\ViewModel)) #2 /var/www/portal/vendor/mezzio/mezzio-laminasviewrenderer/src/LaminasViewRenderer.php(138): Mezzio\LaminasView\LaminasViewRenderer->renderModel(Object(Laminas\View\Model\ViewModel), Object(Laminas\View\Renderer\PhpRenderer)) #3 /var/www/portal/vendor/mezzio/mezzio/src/Response/ErrorResponseGeneratorTrait.php(61): Mezzio\LaminasView\LaminasViewRende in /var/www/portal/vendor/laminas/laminas-view/src/Renderer/PhpRenderer.php on line 492
NGINX proxy (nginx.conf)
user root;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 1024;
}
http {
upstream nginx-web {
server web:8110;
}
upstream nginx-portal {
server portal:8115;
}
upstream nginx-api {
server api:8120;
}
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
server {
listen 80;
server_name proxy;
location /web {
proxy_pass http://nginx-web;
}
location /portal {
proxy_pass http://nginx-portal;
}
location /api {
proxy_pass http://nginx-api;
}
}
}
Server Block (default.conf) portal
server {
listen 8110;
root /var/www/portal/public;
server_name proxy;
location / {
try_files $uri $uri/ /index.php$is_args$args;
index index.php;
}
location ~ ^/.+\.php(/|$) {
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
docker-compose.yml
version: "3.9"
services:
db:
container_name: db
image: mysql:5.7
ports:
- "3306:3306"
volumes:
- "${PROJECT_ROOT}/db:/var/lib/mysql"
- ./conf/db/my.cnf:/etc/mysql/conf.d/my.cnf:ro
env_file:
- .env
networks:
- backend
proxy:
container_name: proxy
image: nginx:mainline-alpine
volumes:
- ./conf/proxy/nginx.conf:/etc/nginx/nginx.conf:ro
ports:
- "80:80"
- "8110:8110"
# - "8115:8115"
- "8120:8120"
depends_on:
- web
- portal
- api
networks:
- backend
web:
container_name: web
image: nginx:mainline-alpine
volumes:
- "${PROJECT_ROOT}/web:/var/www/web"
- ./conf/web/default.conf:/etc/nginx/conf.d/default.conf:ro
depends_on:
- php
networks:
- backend
portal:
container_name: portal
image: nginx:mainline-alpine
volumes:
- "${PROJECT_ROOT}/portal:/var/www/portal"
- ./conf/portal/default.conf:/etc/nginx/conf.d/default.conf:ro
depends_on:
- db
- php
port:
- "8115:8115"
networks:
- backend
api:
container_name: api
image: nginx:mainline-alpine
volumes:
- "${PROJECT_ROOT}/api:/var/www/api"
- ./conf/api/default.conf:/etc/nginx/conf.d/default.conf:ro
depends_on:
- php
networks:
- backend
php:
container_name: php
image: maciejslawik/php-fpm-xdebug:latest
ports:
- "9000:9000"
volumes:
- "${PROJECT_ROOT}/web:/var/www/web"
- "${PROJECT_ROOT}/portal:/var/www/portal"
- "${PROJECT_ROOT}/api:/var/www/api"
- ./conf/php/docker-php-ext-xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini:ro
networks:
- backend
composer:
container_name: composer
image: composer:2
restart: "no"
command: install
volumes:
- "${PROJECT_ROOT}/composer:/app"
- ./composer/composer.json:/app/composer.json
networks:
- backend
phinx:
container_name: phinx
image: vegbrasil/phinx:latest
volumes:
- "${PROJECT_ROOT}/migrations/database/migrations:/app/database/migrations"
- "${PROJECT_ROOT}/migrations/database/seeds:/app/database/seeds"
- ./conf/phinx/phinx.php:/app/phinx.php:ro
env_file:
- .env
depends_on:
- db
restart: "no"
command: "status"
environment:
- TESTS_PHINX_DB_ADAPTER_MYSQL_HOST=db
networks:
- backend
schemaspy:
container_name: schemaspy
image: schemaspy/schemaspy:latest
volumes:
- "${PROJECT_ROOT}/schemaspy/output:/output"
- ./conf/schemaspy/schemaspy.properties:/schemaspy.properties:ro
restart: "no"
depends_on:
- db
networks:
- backend
networks:
backend:
Update
I've tried to xdebug the issue. What I've figured out is that .phtml template file is not being resolved by PhpRenderer.php. Also I'm accessing it with url http://web.local:8115/dashboard however, ideally, I'd like to access it as http://web.local/portal/dashboard.
Suggestions
Could it be that default.conf file is processing only .php files and not .phtml files, however, I doubt it as the issue is, there's a line $file->isReadable() isn't able to process the file whereas I've verified that the file does exist. i.e. summary.phtml.
The permission for this file is also fine.
drwxrwxrwx 1 root root 4096 Oct 31 07:57 .
drwxrwxrwx 1 root root 4096 Oct 31 07:57 ..
-rwxrwxrwx 1 root root 197 Oct 31 07:57 summary.phtml
The issue is: php files are downloaded instead of executing.
I know there are some other similar questions out there to this one. I read many of them but either their scenerios are different or they have no correct answers. I have spent days and tried many ways but still can't figure it out. Therefore I am asking for help. The following are the scenerio, together with the .yml .conf files.
network: nginx-proxy
nginx-proxy:
- nginx (proxy) container
- docker-gen container
- letsencrypt container
web1: (this works fine)
- mysql container
- wordpress container (from wordpress image)
web2: (this has the issue: php files downloaded instead of executing)
- mysql container
- phpfpm container
- nginx container (env: VIRTUAL_HOST, LETSENCRYPT_HOST)
As mentioned above, if I use a Wordpress image, it works successfully. No hassle at all.
However, when I try to set up one with php, nginx and mysql containers myself, those php files will be downloaded instead of executing. (html files can be executed)
create network:
docker network create nginx-proxy
nginx-proxy: docker-compose.yml
version: '3'
services:
nginx:
image: nginx:1.13.1
container_name: nginx-proxy
ports:
- "80:80"
- "443:443"
volumes:
- conf:/etc/nginx/conf.d
- vhost:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
- certs:/etc/nginx/certs
- ./sites-enabled:/etc/nginx/sites-enabled
labels:
- "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true"
dockergen:
image: jwilder/docker-gen:0.7.3
container_name: nginx-proxy-gen
depends_on:
- nginx
command: -notify-sighup nginx-proxy -watch -wait 5s:30s /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
volumes:
- conf:/etc/nginx/conf.d
- vhost:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
- certs:/etc/nginx/certs
- /var/run/docker.sock:/tmp/docker.sock:ro
- ./nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl:ro
- ./sites-enabled:/etc/nginx/sites-enabled
letsencrypt:
image: jrcs/letsencrypt-nginx-proxy-companion
container_name: nginx-proxy-le
depends_on:
- nginx
- dockergen
environment:
NGINX_PROXY_CONTAINER: nginx-proxy
NGINX_DOCKER_GEN_CONTAINER: nginx-proxy-gen
volumes:
- conf:/etc/nginx/conf.d
- vhost:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
- certs:/etc/nginx/certs
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./sites-enabled:/etc/nginx/sites-enabled
volumes:
conf:
vhost:
html:
certs:
networks:
default:
external:
name: nginx-proxy
nginx.conf
# web1.local
upstream web1.local {
## Can be connected with "nginx-proxy" network
# wordpress_web1
server 192.168.96.3:80;
}
server {
server_name web1.local;
listen 80 ;
access_log /var/log/nginx/access.log vhost;
include /etc/nginx/vhost.d/default;
location / {
proxy_pass http://web1.local;
}
}
server {
server_name web1.local;
listen 443 ssl http2 ;
access_log /var/log/nginx/access.log vhost;
return 500;
ssl_certificate /etc/nginx/certs/default.crt;
ssl_certificate_key /etc/nginx/certs/default.key;
}
# web2.local
upstream web2.local {
## Can be connected with "nginx-proxy" network
# nginx_web2
server 192.168.96.7:80;
}
server {
server_name web2.local;
listen 80 ;
access_log /var/log/nginx/access.log vhost;
location / {
proxy_pass http://web2.local;
}
}
server {
server_name web2.local;
listen 443 ssl http2 ;
access_log /var/log/nginx/access.log vhost;
return 500;
ssl_certificate /etc/nginx/certs/default.crt;
ssl_certificate_key /etc/nginx/certs/default.key;
}
sites-enabled/web2.conf
(I also tried to put this part in default.conf but it didn't work)
server {
index index.php index.html index.htm;
root /var/www/html;
location ~ \.php$ {
try_files $uri $uri/ /index.php$is_args$args;
fastcgi_pass phpfpm_web2:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
apps:
web1 (Wordpress): docker-compose.yml (This works fine)
version: "3"
services:
mysql_web1:
container_name: mysql_web1
image: mysql:5.7
restart: always
volumes:
- db_data_web1:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: db1
MYSQL_USER: user1
MYSQL_PASSWORD: password
wordpress_web1:
container_name: wordpress_web1
image: wordpress:latest
restart: always
expose:
- 80
depends_on:
- mysql_web1
environment:
VIRTUAL_HOST: web1.local
LETSENCRYPT_HOST: web1.local
LETSENCRYPT_EMAIL: foo#web1.local
WORDPRESS_DB_HOST: mysql_web1:3306
WORDPRESS_DB_USER: user1
WORDPRESS_DB_PASSWORD: password
volumes:
db_data_web1:
networks:
default:
external:
name: nginx-proxy
web2: docker-compose.yml
version: "3"
services:
mysql_web2:
container_name: mysql_web2
image: mysql:5.7
restart: always
ports:
- 3306
expose:
- 3306
volumes:
- db_data_web2:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: db2
MYSQL_USER: user2
MYSQL_PASSWORD: password
phpfpm_web2:
container_name: phpfpm_web2
image: php-fpm:latest
restart: always
ports:
- 9000
expose:
- 9000
links:
- mysql_web2
depends_on:
- mysql_web2
volumes:
- ./code:/var/www/html
nginx_web2:
container_name: nginx_web2
image: nginx:1.13.1
restart: always
ports:
- 80
expose:
- 80
links:
- phpfpm_web2
depends_on:
- phpfpm_web2
volumes:
- ./code:/usr/share/nginx/html
environment:
VIRTUAL_HOST: web2.local
VIRTUAL_PORT: 80
LETSENCRYPT_HOST: web2.local
LETSENCRYPT_EMAIL: foo#web2.local
volumes:
db_data_web2:
networks:
default:
external:
name: nginx-proxy
in php-fpm.d/www.conf, I tried the following ways, but none of them worked.
listen = 127.0.0.1:9000
listen = php_container_ipaddress:9000
listen = 9000
Many thanks in advance for your help!
everyone.
I have some problems with launching Docker containers.
The final task is:
nginx with 80 and 443 ports as a reverse proxy to localhost:3000 (it's ok);
node.js with 3000 port is frontend (it's ok);
php-fpm with 9000 port and domain.con/api url (it's not working);
So, the main problem is with nginx.conf:
upstream app {
server app:3000;
}
server {
listen 80;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
location / {
try_files $uri #app;
}
location /api {
try_files $uri /index.php?$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass api:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location #app {
proxy_pass http://app;
}
}
When I try to get to localhost — it's ok, node.js is working fine;
But when I try to get to localhost/api — it gives me an error that file not found.
docker-compose looks like:
version: '3'
services:
api:
container_name: api
build:
context: ./api
dockerfile: Dockerfile
restart: unless-stopped
volumes:
- ./api:/var/www
- ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
ports:
- '9000:9000'
networks:
- app-network
app:
container_name: app
build:
context: ./app
dockerfile: Dockerfile
restart: always
ports:
- '3000'
volumes:
- ./app:/app
networks:
- app-network
nginx:
container_name: nginx
image: nginx:alpine
restart: unless-stopped
volumes:
- ./api:/var/www
- ./nginx/:/etc/nginx/conf.d
ports:
- '80:80'
depends_on:
- app
- api
networks:
- app-network
networks:
app-network:
driver: bridge
I've been setting up reverse proxies with apache and nginx on numerous occasions and I always found this activity time consuming (not easy to test and debug).
Since I started to work with docker and docker-compose, I found a much easier way to setup a reverse proxy service and now can spend my time on the apps. This easy way is to make use of a Traefik service in your docker compose file:
version: "3"
services:
reverseproxy: # see https://docs.traefik.io/#the-traefik-quickstart-using-docker
image: traefik:v2.2
command: --providers.docker
ports:
- "8082:80"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
backend:
image: tutum/hello-world
expose:
- 80
labels:
traefik.http.routers.back.rule: Path(`/api`)
traefik.http.routers.back.middlewares: back-stripprefix
traefik.http.middlewares.back-stripprefix.stripprefix.prefixes: /api
frontend:
image: nginx
volumes:
- ./www:/usr/share/nginx/html/:ro
expose:
- 80
labels:
traefik.http.routers.front.rule: Path(`/`)
As you can see, all reverse proxy rules are specified as labels on target containers. Traefik does the reverse proxy job quite well, handling correctly HTTP/2, websockets, forwarding headers, ... It's quite a time saver.
I'm trying to run my symfony app with docker. I have downloaded this bundle eko/docker-symfony
I have copy my symfony project inside of my docker directory.
If I refresh with localhost, I have this error: File not found.
If I put port 81 after localhost the page of Kibana will shop up.
When I run docker ps, I have noticed that the IP of all my containers is 0.0.0.0
docker-compose.yml
version: '2'
services:
db:
image: mysql
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: symfony
MYSQL_USER: symfony
MYSQL_PASSWORD: symfony
php:
build: ./php-fpm
expose:
- "9000"
volumes:
- ./symfony:/var/www/symfony
- ./logs/symfony:/var/www/symfony/app/logs
links:
- db
nginx:
build: ./nginx
ports:
- "80:80"
links:
- php
volumes_from:
- php
volumes:
- ./logs/nginx/:/var/log/nginx
elk:
image: willdurand/elk
ports:
- "81:80"
volumes:
- ./elk/logstash:/etc/logstash
- ./elk/logstash/patterns:/opt/logstash/patterns
volumes_from:
- php
- nginx
symfony.conf
server {
server_name symfony.dev;
root /var/www/symfony/web;
location / {
try_files $uri #rewriteapp;
}
location #rewriteapp {
rewrite ^(.*)$ /app.php/$1 last;
}
location ~ ^/(app|app_dev|config)\.php(/|$) {
fastcgi_pass php-upstream;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
error_log /var/log/nginx/symfony_error.log;
access_log /var/log/nginx/symfony_access.log;
}
I think the problem is port 80. This probably looks on your host for a file.
You can either try to run nginx under a different port f.e. 8001
nginx:
build: ./nginx
ports:
- "8001:80"
and call
http://localhost:8001
or use a hosts name. To quote the readme of eko/docker-symfony
...and do not forget to add symfony.dev in your /etc/hosts file.
like
127.0.0.1 symfony.dev
Then you can call
http://symfony.dev
I am trying to create two docker containers. One would contain nginx, and another would contain php-fpm. Here is my docker-compose.yml:
version: '2'
services:
nginx:
build: ./nginx
ports:
- "80:80"
- "443:443"
fpm:
build: ./php
volumes:
- ./php/code:/var/www/html/
NGINX
Here is my Dockerfile for the nginx container:
FROM nginx:latest RUN rm /etc/nginx/conf.d/default.conf COPY
./default.conf /etc/nginx/conf.d/
And, here is my default.conf:
server {
listen 80;
server_name localhost;
root /var/www/html;
error_log /var/log/nginx/localhost.error.log;
access_log /var/log/nginx/localhost.access.log;
location / {
# try to serve file directly, fallback to app.php
try_files $uri /app.php$is_args$args;
}
location ~ ^/.+\.php(/|$) {
fastcgi_pass fpm:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
}
This is all my nginx configuration.
PHP
Here is the Dockerfile in the ./php directory:
from php:fpm
COPY ./code/ /var/www/html/
Inside the ./code directory, i have a file named app.php that contains phpinfo().
The Problem
I run docker-compose up and when I try to open 192.168.99.100 (the IP of the docker machine in which docker engine is running), I get File not found. I have also tried 192.168.99.100/app.php, but it's the same.
What am I configuring wrong? I saw in an example on the Internet that the PHP files must live in the nginx container, but that doesn't make any sense since as far as I know, php-fpm is the process that must have access to those files.
The reason for your 404 error is that your Nginx container has no files in it.
You must link the same files you linked into the PHP-FPM container into the Nginx container:
version: '2'
services:
nginx:
build: ./nginx
ports:
- "80:80"
- "443:443"
volumes:
- ./php/code:/var/www/html/
fpm:
build: ./php
volumes:
- ./php/code:/var/www/html/
When the request reaches the web-server, the file must at least exist before the Nginx can pass the request along to the PHP-FPM container. You could even make the folder read-only for the Nginx container:
version: '2'
services:
nginx:
build: ./nginx
ports:
- "80:80"
- "443:443"
volumes:
- ./php/code:/var/www/html/:ro
fpm:
build: ./php
volumes:
- ./php/code:/var/www/html/
After doing what has been suggested in the other answer and spending about six hours or more on this issue, I found that the reason my set up wasn't working was because docker-compose up does not rebuild your images, so the configuration in the container was an older version.
So, fixing this was as easy as docker-compose build and then docker-compose up.
Sorry for taking everyone's time.