Simple LAMP Stack using Docker

posted in: Linux | 1

I downloaded a docker image:

docker pull ubuntu:14.04

Started the image running a bash console:

docker run -i -t ubuntu:14.04 /bin/bash

This dropped me into a bash shell where I installed my LAMP stack:

apt-get update
apt-get install fish
apt-get install apache2
apt-get install php5
apt-get install mysql-server

I want to start mysql and apache when I start my docker image. For this purpose, I created a I needed a foreground process to keep the session open, as well as a method to launch the relevant services. For this, I used supervisor

apt-get install supervisor

The following conf files was added to the supervisor conf.d folder (/etc/supervisor/conf.d on Ubuntu 14.04)

start-apache2.conf

[program:apache2] 
command=/usr/sbin/apache2ctl -D FOREGROUND 
numprocs=1 
autostart=true 
autorestart=true

start-mysqld.conf

[program:mysqld]
command=mysqld_safe
numprocs=1
autostart=true
autorestart=true

All that needed to be done is to get supervisor to launch at startup. I created a startup script that can be passed as a input to docker at runtime. The script is named start.sh and located in the root of my docker image.

#!/bin/bash
/usr/bin/supervisord -n

The process can be described as follows:

  1. Docker calls supervisor as a foreground process
  2. Supervisor starts mysql and apache

Finally, I committed the updates:

docker commit 'tag' fasor/lamp

Now to test:

docker run -d -p 80:80 -p 3306:3306 fasor/lamp /start.sh

Yes…I know that all this can easily be done using a build file. This is the next step and I will post the process as soon as I have figured it out. First principles always helps.

 

One Response

  1. Andre Venter

    Now thats how I want to set up my local development environment, but in one batch script

Leave a Reply