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.comRUN yum -y update; yum clean all
RUN yum -y install httpd; yum clean all
RUN echo “Apache” » /var/www/html/index.htmlEXPOSE 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 phpCMD [“/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.
Related Articles:
- 2014/12/09 PHP Image gallery with fancybox.
- 2014/11/03 Search CVE – web interface with php
- 2014/08/18 Apache server-status – better looking
- 2014/05/09 terminal in browser.
- 2014/03/19 Sandbox Firefox – First step to security
Authored By Amit Agarwal
Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.