Migrating applications across Cloud Service Providers using Docker

 In Orchestration


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 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.

  3. Application Containerization using Docker:

    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.

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.

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

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.

#!/bin/bash
/update_siteurl.sh
exec supervisord -n

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.

Recent Posts
Showing 2 comments
  • google authorship wordpress
    Reply

    Hello! This is my 1st comment here so I just wanted to give a quick
    shout out and tell you I really enjoy reading
    through your blog posts. Can you recommend any
    other blogs/websites/forums that go over the same topics?
    Thank you so much!

  • NatashaJaine
    Reply

    Now a days cloud is the unique way in approaching businesses to gain profits along with easy and effective task completion. Almost many IT companies irrespective of the scale of its size around the world are migrated to cloud-based Microsoft 365 solutions because of its huge benefits. A cloud service creates an environment where more companies or projects can work together which eventually leads to a huge rate of returns to run a business in.

Leave a Comment

Start typing and press Enter to search