Docker for that old software you can not update!

So I host a few websites for friends and family and as always you have one person who runs old software that they just do not want to update. The software in question this time is Gallery http://galleryproject.org a php photo gallery that stopped producing updates 2014-06-20. Every time I updated by Ubuntu server I worried about how much trouble it was going to be to make sure it still worked. The fix run the damn thing in docker! Starting with a backup of the gallery web directory from my old server I put it into /home/websites/gallery_example-com/gallery/html.

Ok first decided that the old php version in Centos 5 would be a good fit and decided to start from there and to make it easier I decided to look at the CentOS-Dockerfiles from

https://github.com/CentOS/CentOS-Dockerfiles/blob/master/httpd/centos6/Dockerfile

Knowing I wanted to run CentOS 5 I decided to rebuild the Docker image using this updated Dockerfile in my project directory ~/Development/gallery_docker/Dockerfile

FROM centos:5.11
MAINTAINER Joshua Miller
LABEL Vendor=”CentOS” \
License=GPLv2 \
Version=2.4.6-40

RUN yum -y update && \
yum -y install httpd && \
yum clean all

EXPOSE 80

# Simple startup script to avoid some issues observed with container restart
ADD run-httpd.sh /run-httpd.sh
RUN chmod -v +x /run-httpd.sh

CMD [“/run-httpd.sh”]

I also need the file run-httpd.sh that I put into ~/Development/gallery_docker/run-httpd.sh

#!/bin/bash

# Make sure we’re not confused by old, incompletely-shutdown httpd
# context after restarting the container. httpd won’t start correctly
# if it thinks it is already running.
rm -rf /run/httpd/* /tmp/httpd*

exec /usr/sbin/apachectl -DFOREGROUND

Now I had to build the the docker image in ~/Development/gallery_docker/ with the tag jassinpain/gallery_example:1 so we can version this sucker.

docker build . -t jassinpain/gallery_example:1

And run the image, exposing container port 80 via host 8080 for now as we do not have our haproxy configured yet at this point.

docker run -d –name gallery_example -p 8080:80 jassinpain/gallery_example:1

At this point I was able to browse to http://server_ip:8080/ and see the sample webpage was up and running

Next I decided to clean up, then restart with a bind to my gallery directory to the Apache DocRoot.

docker stop gallery_example
docker rm gallery_example
docker run -d –name gallery_example -p 8080:80 -v /home/websites/gallery_example-com/gallery/html:/var/www/html jassinpain/gallery_example:1

I was luck there was a simple README.html in my /home/websites/gallery_example-com/gallery/html directory so once the image was up I was able to test Apache was still working by browsing to http://server_ip:8080/README.html

From here I needed to do some debugging so I needed to drop into the container console with the following command.

docker exec -i -t gallery_buckhornskinners /bin/bash

I quickly realized I forgot to add php, oops I decided to make quick fix by installing php and some supporting software that I know gallery want and exited the image shell.

yum -y install php53 php53-cli php53-common php53-mysql ImageMagick gd
exit

I needed to restart Apache and since this image does not have a init system the quickest way was to just restart the Docker container.

docker restart gallery_example

At this point I was able to browse to http://server_ip:8080/ and presented with the config page of gallery. As I stepped through I realized that the mysql server details needed to be updated. The wonderful thing about using the bind volume meant I could just use vi to update the /home/websites/gallery_example-com/gallery/html/config.php and update the hostname which is really the DB server.

$storeConfig[‘hostname’] = ‘172.17.0.1’;

From here I was able reload http://server_ip:8080/ and was good to go!

The final steps was to make a clean Docker image by updating the Dockerfile to add the php packages.

FROM centos:5.11
MAINTAINER Joshua Miller
LABEL Vendor=”CentOS” \
License=GPLv2 \
Version=2.4.6-40

RUN yum -y update && \
yum -y install httpd php53 php53-cli php53-common php53-mysql ImageMagick gd && \
yum clean all

EXPOSE 80

# Simple startup script to avoid some issues observed with container restart
ADD run-httpd.sh /run-httpd.sh
RUN chmod -v +x /run-httpd.sh

CMD [“/run-httpd.sh”]

And then rebuild the image:

docker build . -t jassinpain/gallery_example:2

Stop the old image, clean it up, and start with the new image

docker stop gallery_example
docker rm gallery_example
docker run -d –name gallery_example -p 8080:80 -v /home/websites/gallery_example-com/gallery/html:/var/www/html jassinpain/gallery_example:2

And then verify by browsing to http://server_ip:8080/

I then put it behind a haproxy image to allow me to add more projects like may flask-sample, but thats another post!