Running Apache and PHP in a CentOS 7 Docker container

Drew Sears edited this page Feb 28, 2017 · 1 revision

Start the new project:

mkdir phpdemo
cd phpdemo
nano Dockerfile

Create Dockerfile:

FROM centos:7
RUN yum -y update && \
    yum -y install httpd php
ADD index.php /var/www/html/
CMD /usr/sbin/apachectl -D FOREGROUND

Create index.php:

<?php phpinfo(); ?>

Build the image:

docker build -t phpdemo .

Run it, detach, and expose port 80 as 9999.

docker run -d -p 9999:80 phpdemo

Test it out:

http://localhost:9999

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.