Need help?

Our experts will login to your server within 30 minutes to fix urgent issues.

We will keep your servers stable, secure and fast at all times for one fixed price per month.

How we simplified Magento development and deployment process using Docker

How we simplified Magento development and deployment process using Docker

Magento is one of our favorite platforms to develop secure, feature rich eCommerce websites. Since 2008 we’ve developed for and supported Magento shops that ranged from small cake shops to large fashion houses. It has been a fun ride, but it also brought its own set of technical and management challenges. This is the story of how we used Docker to make our lives easier, and how it can work for you too.

Long term support is a part of our Magento development services. To facilitate faster patching and feature development, we maintain full code repositories of the sites we support. A lot of these sites run old versions of Magento (ranging from v1.6.x to v1.8.x) due to reasons as varied as “web host doesn’t have the latest PHP” to “I don’t want to upgrade just yet”. This led us into maintaining different server environments for Dev, QA and Staging environments for each of these websites.

VPS servers worked great when we only had a few websites to support. However, with a growing list of sites to support, the time spent on keeping the Dev, QA and Staging in sync and compatible with each other kept increasing and that affected our speed of delivery.

We needed a solution better than traditional VPS, but with the ease and economy of container server virtualization. So we were excited to see the popularity of Docker and its new cousin Rocket. Docker looked like the better choice because of its extensive ecosystem, and we gave it a go.

Read : How to speed up web app deployment using Docker

Magento with Docker

For those who are unfamiliar with Docker, it is a light weight container technology that can quickly create server instances based on a configuration template.

Why is it important? Because it negates the need to maintain server environments. Everything from Dev, QA, Staging and Live can be created afresh from a shared server specification. There’s no chance of differences in configuration because the server images are exactly the same.


How does it work?

Let’s say you have a Magento site that is up for a theme modification. All you have to do is to execute a git clone to pull the latest version of the website code into your Dev/QA/Stage machine and run a docker-compose up to create a replica environment of the live server. Yes, that easy!

Assuming you’ve already installed Docker, let’s take a look at the steps to create Magento sites on the fly.


Create a Dockerfile to replicate the Live environment

A lot of the websites we maintain are hosted in servers managed by the hosting providers, which means we do not have control over which version of software is installed in them. So, we always assume the live server environment as the golden standard, and work from there.

I’ll demonstrate a simple case. A Magento website that runs on Ubuntu 14.01, and uses the latest version of PHP and Apache can be replicated using a 3 line Docker specification file (known as Dockerfile) like below:

FROM ubuntu:trusty
RUN apt-get update \
        && apt-get -y install php5 php5-mysql php5-curl php5-mcrypt php5-cli php5-gd \
        && php5enmod mcrypt \
        && a2enmod rewrite
ADD /tmp/mageshop01/html/ /var/www

The FROM directive says what the base image should be. The RUN command installs all the necessary packages from Ubuntu repository, and the ADD command copies the contents of /tmp/mageshop01/html/ (to which I earlier cloned the website git repo) to /var/www/html of the server instance.

Looks easy enough, right? You can do further customizations on the PHP and Apache configuration files using more RUN commands, but essentially this is the basic approach.


Create a Docker compose script to build the website

Now that we have a web server, we need a database server for the shop data. You can create one and link it to the web server using a docker-compose.yml specification file like this:

  build: .
  command: apachectl -D FOREGROUND
    - "8081:80"
    - magedb
    - /tmp/mageshop01/html/:/var/www
  image: orchardup/mysql
    MYSQL_DATABASE: magento
    MYSQL_USER: mage
    MYSQL_PASSWORD: dbpass

What it basically does is to build a web server (mageweb) using the Dockerfile we saw earlier, create a database server (magedb) using the server image “orchardup/mysql”, link them together, and make the web server listen at port 8081.

Now with a simple docker-compose up command, the web and database servers comes online with the latest code from your repo.

With small changes to the specification files, you can install any version of any software and make custom configuration changes in the Dev, QA, Stage and (if supported) Live servers.

We started by using Docker on a couple of projects, and then soon adopted it on all our Magento projects. Gone are the days in which we ran our VPS servers on full capacity. Now we create containers only when we need it, and do not spend time troubleshooting environment differences.


Spreading the light

We were pretty happy with how Docker made our lives easier. Guess what made us happier? One of our customers who provided Magento hosting, and custom Magento development services mentioned the same issues we faced. We pitched the Docker DevOps idea to them, and now they too are happy campers of the Docker-Magento club.
How much time do you spend managing your servers?


Bobcares DevOps engineers routinely help application developers configure their infrastructure and optimize their DevOps process.



Submit a Comment

Your email address will not be published. Required fields are marked *

Docker Support

Spend time on your business, not on your servers.

Managing a server is time consuming. Whether you are an expert or a newbie, that is time you could use to focus on your product or service. Leave your server management to us, and use that time to focus on the growth and success of your business.

TALK TO US Or click here to learn more.