Quantcast
Channel: Webkul Blog
Viewing all articles
Browse latest Browse all 5537

Dockerize Joomla : Virtualize your CMS within a light-weighted container

$
0
0

Why we need Docker Containers : Take A Quick Look 

Dependency hell is something that the application developers are dealing with for a very long time and what it means is, i build my application on my development machine, it works great, then i deploy my application to the production environment but it doesn’t work.

Hey developer, your application doesn’t work in our environment, fix it. Hey sysadmin, it works fine in my environment, why does’nt it work in your environment? Therefore, it leaves system admin and developers pointing fingers at each other. Here, the concept of docker containers came into picture.

Containers are completely isolated environment.The application only needs to run inside the container which means that the operating system,underlying host and the environment that it runs on is completely abstracted from the application and therefore it successfully solves the problem of dependencies.

So if you are also dealing with such kind of problems within your content management system, this blog will definitely help you out. Here, we are taking joomla as a CMS which enables you to build websites and powerful online applications. Here we go !!

Understanding the scenario :

When using docker, we start with a base image. We boot it up, do changes and the changes are saved in layers forming another image. Basically, there are following two ways to create an image :-

  • Interactively, by running a shell from a base image and manually installing the required software.
  • Imperatively, by defining a series of commands inside a Dockerfile.

The first approach is undoubtedly better when experimenting or finding your feet, but when you want to start building reliable, reusable images I’ve found using a Dockerfile a must. So, we will go ahead with the latter one.

An instance of an image is called container. You have an image, which is a set of layers as you have described it by yourself. If you start this image, you have a running container of this image. You can have many running containers of the same image. To see all of your images and containers, run the following commands :-

docker images

docker ps

Dockerfile of our base image : webkul/joomla

FROM ubuntu:14.04
MAINTAINER Naina Johari <naina.johari379@webkul.com> 

# Update existing packages & install LAMPSTACK
RUN apt-get update
RUN apt-get install -y lamp-server^ && \
    apt-get install -y wget curl unzip 
RUN apt-get install -y libapache2-mod-php5 php5-mcrypt php5-gd pwgen


# Download Joomla
ADD https://github.com/joomla/joomla-cms/releases/download/3.4.1/Joomla_3.4.1-Stable-Full_Package.zip /tmp/

# Remove previous files of default document root
RUN rm -rf /var/www/html/*

# Extract Joomla
RUN cd /tmp && unzip -q Joomla*.zip -d /var/www/html

# Grant permission of the directory to apache2
RUN chown -R www-data:www-data /var/www/html && \
chmod -R 755 /var/www/html

RUN sed -i -e"s/^bind-address\s*=\s*127.0.0.1/bind-address = 0.0.0.0/" /etc/mysql/my.cnf
RUN apt-get install -y supervisor
RUN mkdir -p /var/log/supervisor
RUN php5enmod mcrypt

ADD startupscript.sh /etc/startupscript.sh
ADD supervisord.conf /etc/supervisor/conf.d/supervisord.conf
ADD adminer.php /var/www/html/joomla
ADD create_mysql_admin_user.sh /create_mysql_admin_user.sh
RUN chmod 755 /create_mysql_admin_user.sh
RUN ./create_mysql_admin_user.sh > /credentials.txt

EXPOSE 80
EXPOSE 3306

CMD ["/usr/bin/supervisord"]

 

Pull our docker image for joomla directly from dockerhub using the following command :-

docker pull webkul/joomla

Check if you have successfully downloaded the image locally on your system :-

docker images

You must find webkul/joomla as an output of this command.

Run a container of this image using the following command :-

docker run -d -p 80:80 -p 3306:3306 webkul/joomla:latest

Note-: No other services should be running on port 80 and 3306 of your host system. If so, change ports in the above docker command. 

Access the URL to install joomla on your system :-

http://server_domain_name_or_IP/joomla

In order to access the credentials of your database, you have to get the container’s console. Run the following command :-

docker exec -it $container_id  bash

You are supposed to run “docker ps” to know container’s id before you run the above command.
Within container,read the content of the file named password.txt to access your mysql database username and password by running :-

cat /password.txt

Once your mysql username and password is known to you, you can simply login to mysql and create database accordingly.

For Reference :- https://hub.docker.com/webkul/joomla

For Source Code :-  https://github.com/webkul/docker_joomla


Viewing all articles
Browse latest Browse all 5537

Trending Articles