today a write about Docker to share a PHP Project with Mod-Rewrite and no Public Application Code and i try to write it in english. I must learn it. 😀 This How-to is written for Puschel from Cranktube.tv. Maybe he will understand the Docker Commands now.
The PHP Project Folder are
The First Step is to open a File names Dockerfile and write the Build Requirements in it.
Here the full Dockerfile Content.
MAINTAINER Manuel ‚Onko‘ Müller <email@example.com>
RUN yum update -y
RUN yum install git curl php -y
RUN yum install httpd -y
RUN yum install php-pdo -y
RUN yum install php-pdo_mysql -y
COPY . /var/www
COPY httpd.conf /etc/httpd/conf/httpd.conf
CMD httpd && tail -f /var/log/lastlog
We need a OS so i choose CentOS in latest version. This is the First Line
The MAINTAINER is only for Information, who has written this holy shit.
The next RUN Commands update the CentOS and install Git, Curl, PHP, httpd, php-pdo, php-pdo-mysql
PDO is the Database Conector and php_pdo_mysql the Connector for MySQL.
The Copy Command take the Content of the actually Folder in the Docker Container. The Target Folder is /var/www. This is the httpd default Webroot.
Then i copy my own httpd.conf file in the Container to Allow Override and some other Stuff. This File is in the same Folder too.
EXPOSE 80 Open the http Port for the Container so it is possible to connect the container.
CMD httpd && tail -f /var/log/lastlog this command start the httpd service and open a logfile without the tail logfile the httpd will startet and the docker container shutdown if all done.
Now we have a full running PHP Project in this Container.
In my Case i will run it local for development. So i run boot2docker on my Windows Maschine and shared my Development Folder with the Virtual Maschine. So i have access to it with mount Point /c/Users
So i Switch the workdir to my development Project Folder
In this folder are my PHP Code, public code like CSS Images and public PHP Files in subfolder html, my httpd Config and the Dockerfile
So i can build a Container now.
docker build -t myProject .
The dot as the end is the acctually folder i can use follow command too.
docker build -t myProject /c/Users/myPHPCode
Next Command we need is to start the Container.
docker run -p 80:80 -d -i -t myProject
With -p i mapped the container port 80 to the Virtual Maschine Port 80.
Now i have running a PHP Project with the latest code of my Project. But i want to change code and try it out. so i can mount my real local code to the container.
With -v i can mount /var/www with the virtual maschine folder /c/Users/myPHPCode
docker run -p 80:80 -v /c/Users/myPHPCode/var/www -d -i -t myProject
I hope my english is clear enough to understand what i try to explain. 🙂