Ajeet Raina Docker Captain, ARM Innovator & Docker Bangalore Community Leader.

Setting up LAMP stack in a Docker container

1 min read

Yesterday evening I decided to spend time on setting up LAMP( Linux, Apache, MySQL and PHP) stack inside a docker container.

I managed to create a CentOS 7.0 VM with around 50GB space and around 4GB RAM. I had enough containers lying around and so removed few which I no longer needed. Here is the dirty guide on how I was able to setup LAMP stack on my docker system.

Let’s start searching for LAMP.  I just uploaded a LAMP container onto the Docker hub at https://registry.hub.docker.com/u/collabnix/lamp-for-collabnix/

[root@localhost ~]# docker search collabnix
collabnix/lamp-for-collabnix 0
collabnix/puppet4docker A Puppet Ready Docker Image 0
collabnix/puppet-for-docker 0

Let’s pull the docker image:

[root@localhost ~]# docker pull collabnix/lamp-for-collabnix:v1.0
Pulling repository collabnix/lamp-for-collabnix
17d8d9272e36: Pulling image (v1.0) from collabnix/lamp-for-collabnix, endpoint: 17d8d9272e36: Download complete
c50f7e0846e6: Download complete
fd248b999044: Download complete
9f91f850df24: Download complete
ac6b0eaa3203: Download complete
Status: Image is up to date for collabnix/lamp-for-collabnix:v1.0
[root@localhost ~]#

Let’s run the docker image and expose 80:80 port for Apache to work:

[root@localhost ~]#sudo docker run -p 80:80 -t -i collabnix/lamp-for-collabnix:v1.0 /bin/bash

Starting Apache Service:

root@c1b6750b55:/# service apache2 restart
* Restarting web server apache2
/usr/sbin/apache2ctl: 87: ulimit: error setting limit (Operation not permitted)
Setting ulimit failed. See README.Debian for more information.
[ OK ]

In worst case, if you face the above issue, here is the fix:

change /etc/apache2/envvars entry to APACHE_ULIMIT_MAX_FILES=’sleep 0.01′

#service apache2 restart
* Restarting web server apache2 [ OK ]

Starting MySQL:

#service mysql start

* Starting MySQL database server mysqld [ OK ]
* Checking for tables which need an upgrade, are corrupt or were
not closed cleanly.

Now, you can exit the container while leaving it running by pressing ctrl + p then ctrl + q.

Enter the IP address in a web browser to test the site.

Done !!! You have LAMP stack working in a Docker container.

Have Queries? Join https://launchpass.com/collabnix

Ajeet Raina Docker Captain, ARM Innovator & Docker Bangalore Community Leader.

Leave a Reply

Your email address will not be published.

© Copyright Collabnix Inc

Built for Collabnix Community, by Community