apache in docker to serve local website

2015-01-05 296 words 2 mins read

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

FROM fedora
MAINTAINER “Scott Collier” scollier@redhat.com

RUN yum -y update; yum clean all
RUN yum -y install httpd; yum clean all
RUN echo “Apache” » /var/www/html/index.html

EXPOSE 80

# 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

CMD [“/run-apache.sh”]

 

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:

#!/bin/bash -
#===============================================================================
#
#          FILE: docker_firefox.sh
#
#         USAGE: ./docker_firefox.sh
#
#   DESCRIPTION:
#
#       OPTIONS: ---
#  REQUIREMENTS: ---
#          BUGS: ---
#         NOTES: ---
#        AUTHOR: Amit Agarwal (aka)
#      REVISION:  ---
#===============================================================================

dir="your/desired/directory/with/content/for/website"
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.


author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it