You can run both of them simultaneously with simple docker-compose
version: '3'
services:
#PHP5 Service
app1:
build:
context: .
dockerfile: Dockerfile-php5
container_name: app1
restart: unless-stopped
tty: true
env_file:
- ./.env/php5.env
- ./.env/.env
working_dir: /var/www/project1
networks:
- app-network
volumes:
- ./project1:/var/www/project1
#PHP7 Service
app2:
build:
context: .
dockerfile: Dockerfile-php7
container_name: app2
restart: unless-stopped
tty: true
env_file:
- ./.env/php7.env
- ./.env/.env
working_dir: /var/www/project2
networks:
- app-network
volumes:
- ./project2:/var/www/project2
#Nginx Service
webserver:
image: nginx:alpine
container_name: webserver
restart: unless-stopped
tty: true
ports:
- "8081:8081" #For Project1
- "8082:8082" #For Project2
networks:
- app-network
volumes:
- ./project1:/var/www/project1
- ./project2:/var/www/project2
- ./nginx/conf.d:/etc/nginx/conf.d/
- ./nginx/log:/var/log/nginx
networks:
app-network:
driver: bridge
and you should use fastcgi to pass requests on your different apps as follow:
#Project1
server {
listen 8081;
index index.php index.html;
error_log /var/log/nginx/api-error-php5.log;
access_log /var/log/nginx/api-access-php5.log;
root /var/www/project1/public;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app1: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 / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
}
and for project2
#Project2
server {
listen 8082;
index index.php index.html;
error_log /var/log/nginx/api-error-php7.log;
access_log /var/log/nginx/api-access-php7.log;
root /var/www/project2/public;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app2: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 / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
}