Docker setup using docker-compse with CentOS6.8 Nginx PHP7.0

Why NOT CentOs7.0?

At this time of writing this, there is an issue with Docker base repo available for CentOs 7.0 has some issue with  PHP7.0. Hopefully in the near future, that will be fixed too.

Docker Compose:

If you want to know what docker-compose is, please read here.

What Happens here?

  • We use Version 2 of docker-compose
  • We have two services called web and php-fpm
  • The port 80 of Web is exposed as 8080 for host os.
  • Nginx configuration is copied to /etc/nginx/conf.d
  • web container has link to php-fpm container. With docker-compose 2, you can use network option too do so…
  • php-fpm has 9000 port exposed.
  • Volums, all the files/directories that are mounted to the container.

What’s in ./container/centos-docker/nginx/centos68/Dockerfile ?

FROM centos:centos6

RUN yum -y update; yum clean all
RUN yum -y install epel-release; yum clean all
RUN yum -y install nginx; yum clean all
RUN echo “daemon off;” >> /etc/nginx/nginx.conf
RUN echo “nginx on CentOS 6 inside Docker” > /usr/share/nginx/html/index.html


CMD [ "/usr/sbin/nginx" ]

What’s in ./container/eght/php7/Dockerfile ?

[sourcecode language="csharp"]

FROM centos:centos6.8

RUN yum install -y epel-release
RUN rpm -Uvh
RUN rpm -Uvh
RUN rpm -Uvh

RUN yum install -y php70w \
php70w-xml \
php70w-mbstring \
php70w-json \
php70w-gd \
php70w-mcrypt \
php70w-fpm \


CMD ["php-fpm", "-F"]


What’s on site.conf ?

[sourcecode language="csharp"]
server {
listen 80;
index index.html index.php;
server_name test.local;
error_log  /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/html/backend;

location ~ \.php$ {
#try_files $uri =404;
#fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php-fpm:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;


What’s on php-fpm.conf?

[sourcecode language="csharp"]

user = apache
group = apache
;;;This is the main change that is done from original file, so it’s not restricted to certain ip..
;;; Best to take the original file and to make those changes..
listen =

;;And the line below was commented out
;listen.allowed_clients =

pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35

catch_workers_output = yes

php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on
php_value[session.save_handler] = files
php_value[session.save_path]    = /var/lib/php/session
php_value[soap.wsdl_cache_dir]  = /var/lib/php/wsdlcache


Thats it..

Now check the browser test.local:8080 and see if index.php file is executed…

Note: Tested in Ubuntu 16.04 as host..

This entry was posted in Docker. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>