In previous article we have discuss how to run nginx and php-fpm in single container using supervisord. With base php image, we need to install some packages such as nginx and supervisord. In this article we will discuss how to running with separate official image.

previous article:


  1. Docker Engine installed on OS, linux / mac / windows

Create one example PHP file

i will create index.php file

<?php phpinfo();

Create Dockerfile

dockerfile for php-fpm

in this file we will copy project file called as ‘index.php’ into the image and make simple script to move from temporary directory into volume.


FROM php:8.2-fpm-buster

RUN mkdir -p /home/
COPY index.php /home/index.php
COPY /root/

RUN chmod +x /root/

CMD ["/bin/bash", "-c", "/root/;php-fpm" ]

dockerfile for nginx

in the nginx’s dockerfile just copy the host configuration.


FROM nginx:stable-bullseye

COPY default /etc/nginx/conf.d/default.conf

Create Necessary Files


mv /home/* /var/www/html/


server {
         listen       80;
         server_name  _;
         root         /var/www/html/;

         access_log /var/log/nginx/access.log;
         error_log  /var/log/nginx/error.log error;
         index index.html index.htm index.php;

         location / {
                      try_files $uri $uri/ /index.php$is_args$args;

         location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass php:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
            include fastcgi_params;

so we have like this

❯ tree
├── Dockerfile-nginx
├── Dockerfile-php
├── default
├── index.php

0 directories, 5 files

Building the docker images

docker build -t . -f Dockerfile-nginx
docker build -t . -f Dockerfile-php

Create Volume and Network

volume used to store project’s files and the network used to communicate between nginx and php-fpm

docker volume create php
docker network create php

Run docker container

docker run -d --name php --network php -v php:/var/www/html
docker run -d --name nginx --network php -v php:/var/www/html

So we have 2 live containers, guys

Access the website

for testing, we can access the website