Create HTTPD / PHP Docker – Centos 7
Quote from moshe on 24/10/2020, 7:12 amProblem
User wants to create docker container with httpd, PHP and various modules
Solution
Create a file called Dockerfile in the directory for the build (or download the docker file and rename to Docker without extension ) and copy this contents
FROM centos:7
# Install Apache
RUN yum -y update
RUN yum -y install httpd httpd-tools# Install EPEL Repo
RUN rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm \
&& rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm# Install PHP
RUN yum -y install php72w php72w-bcmath php72w-cli php72w-common php72w-gd php72w-intl php72w-ldap php72w-mbstring \
php72w-mysql php72w-pear php72w-soap php72w-xml php72w-xmlrpc# Update Apache Configuration
RUN sed -E -i -e ‘/<Directory “\/var\/www\/html”>/,/<\/Directory>/s/AllowOverride None/AllowOverride All/’ /etc/httpd/conf/httpd.conf
RUN sed -E -i -e ‘s/DirectoryIndex (.*)$/DirectoryIndex index.php \1/g’ /etc/httpd/conf/httpd.confEXPOSE 80
# Start Apache
CMD [“/usr/sbin/httpd”,”-D”,”FOREGROUND”]Build the Docker
docker build -t image_httpd .
Run the Docker
Specify the directory with your site for the httpd server to mount as volume inside the container it will be mounted to /var/www/html which was specified as the httpd root directory in the Docker file. the port of the container is 8080 ( just incase httpd server exists on port 80 ).
docker run -tid -p 8080:80 –name=container_httpd -v /home/website:/var/www/html image_httpd
change the value to 80:80 if you want to run as standard httpd
Test
use your curl or your favorite browser to access the server
Problem
User wants to create docker container with httpd, PHP and various modules
Solution
Create a file called Dockerfile in the directory for the build (or download the docker file and rename to Docker without extension ) and copy this contents
FROM centos:7
# Install Apache
RUN yum -y update
RUN yum -y install httpd httpd-tools# Install EPEL Repo
RUN rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm \
&& rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm# Install PHP
RUN yum -y install php72w php72w-bcmath php72w-cli php72w-common php72w-gd php72w-intl php72w-ldap php72w-mbstring \
php72w-mysql php72w-pear php72w-soap php72w-xml php72w-xmlrpc# Update Apache Configuration
RUN sed -E -i -e ‘/<Directory “\/var\/www\/html”>/,/<\/Directory>/s/AllowOverride None/AllowOverride All/’ /etc/httpd/conf/httpd.conf
RUN sed -E -i -e ‘s/DirectoryIndex (.*)$/DirectoryIndex index.php \1/g’ /etc/httpd/conf/httpd.confEXPOSE 80
# Start Apache
CMD [“/usr/sbin/httpd”,”-D”,”FOREGROUND”]
Build the Docker
docker build -t image_httpd .
Run the Docker
Specify the directory with your site for the httpd server to mount as volume inside the container it will be mounted to /var/www/html which was specified as the httpd root directory in the Docker file. the port of the container is 8080 ( just incase httpd server exists on port 80 ).
docker run -tid -p 8080:80 –name=container_httpd -v /home/website:/var/www/html image_httpd
change the value to 80:80 if you want to run as standard httpd
Test
use your curl or your favorite browser to access the server
Uploaded files: