Bobcares

How we simplified Magento development and deployment process using Docker

by | Oct 6, 2015

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:

mageweb:
  build: .
  command: apachectl -D FOREGROUND
  ports:
    - "8081:80"
  links:
    - magedb
  volumes:
    - /tmp/mageshop01/html/:/var/www
magedb:  
  image: orchardup/mysql
  environment:
    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.

SEE HOW BOBCARES CAN HELP YOUR DEVOPS

0 Comments

Submit a Comment

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

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF