preload
Sep 11

It has been a while since last post 🙂 The site is running on AWS nowadays and i wanted to test out my nginx and php-fpm setup on CentOS7. I did not want to install virtual machine from AMI image and reconfigure the server all over again. This is where docker came handy. Here are some features I noticed during the test.

So the target was to build container with PHP5.4 without affect to the actual site. For this, docker has nice feature which allows you to map directory from host machine to the container.

Here is the Dockerfile to build CentOS7 image with my comments.

FROM centos:centos7
MAINTAINER J.Berg contact@mceith.com
RUN rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
RUN yum install epel-release -y
RUN yum update -y && yum install nginx php-fpm php-mysql -y
RUN mkdir /var/wwwlogs
# Copy the original settigs. Note that the files must be inside the build directory.
COPY nginx.conf /etc/nginx/nginx.conf
COPY sites-enabled /etc/nginx/sites-enabled
COPY sites-available /etc/nginx/sites-available
COPY conf.d /etc/nginx/conf.d
ADD run.sh /run.sh
# Do not start nginx as daemon.
RUN sed -i '1 i\daemon off;' /etc/nginx/nginx.conf
RUN sed -ie 's/apache/mceith/g' /etc/php-fpm.d/www.conf
# Match user id with running system for php-fpm.
RUN groupadd -g 501 mceith && useradd -M -u 501 -g 501 mceith -s /sbin/nologin
EXPOSE 80
ENTRYPOINT /run.sh

Since container does not have systemd or whatever to handle running processes, we need to make script which starts them for us:

run.sh

#!/bin/bash
/usr/sbin/php-fpm -D && /usr/sbin/nginx

Build the image:


# docker build -t nginx_test .

And run it on port 8080:


# docker run -t -i -d -p 8080:80 -v /var/www/mceith/public_html:/var/www/mceith/public_html -v /var/wwwlogs:/var/wwwlogs nginx_test

Site runs parallel with CentOS6/PHP5.3 on port 8080. Seems to work with CentOS7/PHP5.4 also! 🙂

Tagged with: