I have some backup’s of website on my laptop, which I occasionally want to view. Now, I could have setup apache to serve them directly with VirtualHost or alias but wanted a better solution. So, docker comes to rescue.
First, I installed fedora-dockerfiles and then made some modifications, here they are :
sudo yum install fedora-dockerfiles
After this is done, go to /usr/share/fedora-dockerfiles/apache and make some modification to Dockerfile. After the modifications, the file looks like this
MAINTAINER “Scott Collier” <[email protected]>
RUN yum -y update; yum clean all
RUN yum -y install httpd; yum clean all
RUN echo “Apache” >> /var/www/html/index.html
# Simple startup script to avoid some issues observed with container restart
ADD run-apache.sh /run-apache.sh
ADD php.conf /etc/httpd/conf.d/php.conf
RUN chmod -v +x /run-apache.sh
RUN yum -y install php
Now copy the php.conf file to current directory.
sudo cp /etc/httpd/conf.d/php.conf .
#Build the docker image
docker build --rm -t apache .
#and then quickly test the image like this -
docker run -t -i --rm -p 80:80 apache
#open the site in firefox
firefox -new-tab http://loccalhost
Once you see that the docker is running fine, time to create a script to do this in your desired directory.
I always have “~/bin” in $PATH, so I created ~/bin/docker.sh file with the following contents:
# FILE: docker_firefox.sh
# USAGE: ./docker_firefox.sh
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Amit Agarwal (aka)
# REVISION: ---
echo "Run Ubu website:::"
CID=$(docker run -d -p 80:80 -v $dir:/var/www/html:ro apache)
echo docker CID is $CID
firefox -new-tab http://localhost/index.php
After this time to test:
Just run this script and you should have the contents of current directory in your browser.