Technical

Migrating applications across Cloud Service Providers using Docker

The growing interest in migrating the hosted application stack to cloud brings the obvious question on how seamless can be the application migration process across the service providers instantaneously to get the real benefits of cloud technology in terms of cost effectiveness, elasticity and agility.

There are various ways of migrating application workloads:

  1. Migrating the workload through Open Cloud Standards:

    There are some initiatives in providing interoperability across providers. However the adoption is very slow as cloud providers seek to differentiate each other rather than standardising their services.

  2. SaaS based Cloud Migration Platforms:

    There are quite a few SaaS based migration platforms available. However the process still involves some manual work to complete the migration. Available platforms are integrated with only few public cloud platforms and not all providers and virtualization platforms supports this type of migration.

  3. Application Containerization using Docker:

    A Docker package is technically a virtual machine on its own, though with a limited set of libraries as compared to a full-fledged OS which has its overheads. It enables easy packaging and deployment of workloads. It is purely platform agnostic, the packaged containers can work in Physical, Virtual as well as Cloud platforms.

Let’s go through the process involved in migrating a WordPress application running on a VM powered by VMWare virtualization platform and then migrate the applications to an Openstack instance using Docker.

A: Setting up the Docker environment:

The virtual machine used in this case is an Ubuntu Server 14.04, 64 bit with kernel v 3.8.

Note: Ubuntu precise 12.04 or older versions comes with Linux kernel 3.2 which is not compatible with LXC. Please upgrade the kernel as per the following steps:

sudo apt-get update

sudo apt-get install linux-image-generic-lts-raring linux-headers-generic-lts-raring

sudo reboot

a: Docker installation:

# add docker repository to local keychain

sudo apt-key adv –keyserver hkp://keyserver.ubuntu.com:80 –recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9

sudo sh -c “echo deb https://get.docker.io/ubuntu docker main\

> /etc/apt/sources.list.d/docker.list”

sudo apt-get update

sudo apt-get install lxc-docker

b: Verify Docker installation

sudo docker -v

B: Creating a WordPress Container :

WordPress container has the following components.

 

 a: O/S installation

Run the operating system. We will run the Ubuntu 14.04 operating system in interactive mode to get inside the container.

sudo docker run –t –i ubuntu:14.04 bash

Now we are inside the container and we will install the WordPress container with Mysql, Apache & PHP in the subsequent steps.

b: WordPress Installation

Please refer to the URL for installing WordPress with required pre-requisites.

c: Utility Scripts for application start-up

i: Create file start-apache2.sh with the following content:

#!/bin/bash

source /etc/apache2/envvars

exec apache2 -D FOREGROUND

ii: Create file start-mysqld.sh with the following content:

#!/bin/bash

exec mysqld_safe

iii: Install supervisor process manager to run the apache and mysql scripts.

sudo apt-get install supervisor

iv: Create supervisord-mysqld.conf and add the following:

[program:mysqld]

command=/start-mysqld.sh

numprocs=1

autostart=true

autorestart=true

v: Create supervisord-apache2.conf and add the following:

[program:apache2]

command=/start-apache2.sh

numprocs=1

autostart=true

autorestart=true

vi: Copy supervisord-mysqld.conf & supervisord-apache2.conf to /etc/supervisor/conf.d/

Create a script update_siteurl.sh to assign the SiteURL IP address dynamically, this is required in case of domain name is not used.

#!/bin/bash

/usr/bin/mysqld_safe > /dev/null 2>&1 &

RET=1

while [[ RET -ne 0 ]]; do

echo “=> Waiting for confirmation of MySQL service startup”

sleep 5

mysql -uroot -e “status” > /dev/null 2>&1

RET=$?

done

SITEURL=http://$IP/wordpress

echo “Setting the SITE URL $SITEURL”

mysql -uroot -e “UPDATE wordpress.wp_options SET option_value = ‘$SITEURL’ WHERE option_name = ‘siteurl'”

mysql -uroot -e “UPDATE wordpress.wp_options SET option_value = ‘$SITEURL’ WHERE option_name = ‘home'”

mysqladmin -uroot shutdown

vii: Container start-up option:

                           Let’s create the run.sh to be used for container start-up.

#!/bin/bash

/update_siteurl.sh

exec supervisord -n

Exit the container.

viii: Commit the changes with the following steps.

            Run docker ps –a ,it will display the list of containers along with the latest container.

ix: Commit the changes made to the container:

docker run –m=”Created a WordPress Container” $CONTAINER_ID yourname/repository:tag

C: WordPress verification

Start the WordPress container.

docker run –d –p 80:80 –p 3306:3306 IP=”YOUR IP” yourname/repository:tag /run.sh

              Verify the WordPress installation in the browser.

D: WordPress modification

a: Create a log-in id and add blog to the installed wordpress by accessing wordpress.

b: Stop the container and commit the changes with a new tag.

c: Push the changes to docker repository.

docker push yourname/repository:tag

E: Container Migration to Openstack instance

a: Create an Openstack instance with Ubuntu operating system. We can repeat the previous steps for docker installation and verification as mentioned in the earlier sections.

b: Download and run the WordPress container.

docker run –d –p 80:80 –p 3306:3306 IP=”YOUR IP” yourname/repository:tag /run.sh

We can see the changes made to the WordPress container reflecting in the new instance. we have now migrated a container from VMWare virtualization platform to AWS platform.

Using this process we can migrate the hosted wordpress application to any cloud service providers at ease.

In the next blog we will explore the options of storing the data in a separate container to easily upgrade the components of WordPress without losing the data.

Advertisements

One thought on “Migrating applications across Cloud Service Providers using Docker

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s