Docker Data Containers

November 20th, 2015
10921784526_e02cfdd9ab_z

photo by  www.GlynLowe.com

The appeal of Docker is clear.
The Docker platform enables multiple applications to run concurrently on a single copy of an OS, either deployed directly onto a physical server or as a virtual machine (VM).

One challenge with Docker is having persistent storage for a container especially when that container gets restarted on another VM host and we want it to point to the same data.

Here is a video explaining a little of the problem and possible future solutions.

 

But what if you want a solution now?  A solution now is available with Delphix. If we add in Delphix with Docker we can easily move persistent data and a docker container to a new host.

For the docker container we will use wordpress that leverages a MySQL database for it’s persistent datastore.

In this example I will be using Delphix Express version and the Landshark source and target environment and will be using a wordpress docker container that points to a persistent MySQL data store..

The source and target machines already have docker and MySQL on them, so all we need to do is start MySQL, create a wordpress schema, start docker, get the docker wordpress container, then start a docker container with wordpress and point to the MySQL database.

On the Source
ssh  delphix@source
# password is delphix
su –
# password is delphix
vi /etc/my.cnf
#add line “user=root” then save file
service mysqld start
mysql -u root -p
CREATE DATABASE wordpress;
CREATE USER wordpressuser;
SET PASSWORD FOR wordpressuser= PASSWORD(“password”);
GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser IDENTIFIED BY ‘password';
FLUSH PRIVILEGES;
exit

Then start docker and download the “wordpress” container

service docker start
docker pull wordpress

Start docker wordpress container

docker run -p 80:80 –name wordpress  \
           -e WORDPRESS_DB_HOST=172.16.160.160:3306 \
           -e WORDPRESS_DB_USER=wordpressuser \
           -e WORDPRESS_DB_PASSWORD=password \
           -d wordpress

Now, on the source machine, we have a docker wordpress container using a persistent MySQL database for storage.

Delphix
Now to move this docker container to another host, we can link in the MySQL database to Delphix. Once linkedin, we can provision a copy out to any registered host.
In Delphix, I just click + in the top left to add a datasource. The MySQL database should show up in the top of source.
Screen Shot 2015-11-19 at 4.49.43 PM
Screen Shot 2015-11-19 at 4.50.17 PM
Once linking is finished we can provision the MySQL out to another target machine and startup a new docker container pointing to this new virtual MySQL database (VDB).
I just click on the dSource on the left, then on the right click on provision and choose the target machine and a port. I’ll use 3306 for the port.

Now I have a thin clone of the MySQL database, a virtual database (VDB), running on the target machine. I just need to create a docker wordpress container to use it.

 Target
service docker start
docker pull wordpress

docker run -p 80:80 –name wordpress \

           -e WORDPRESS_DB_HOST=172.16.160.161:3306 \
           -e WORDPRESS_DB_USER=wordpressuser \
           -e WORDPRESS_DB_PASSWORD=password \
           -d wordpress

Now I can access my wordpress blog on my target machine and modify it separately from the source. If the target machine goes down, I can migrate the VDB to another host and startup the container there and point the wordpress container to the same VDB now running on a new host.

One other change I made on the target VDB is changing the siteurl and home to be the new IP of the target machine:

mysql -u wordpressuser -ppassword -h 172.16.160.161 -P 3306 wordpress << EOF

update wp_options set option_value=’http://172.16.160.161′ where option_id<3;

select option_value,option_id from wp_options where option_id < 4;

EOF

 

From here we can set up architectures where the source is hosted directly on Delphix and Delphix can manage version controlling the source MySQL database and WordPress application.

We can spin out multiple VDBs in minutes for almost no storage to give to multiple developers to try modifications and merges of changes on.

 

 


Uncategorized

  1. Trackbacks

  2. No trackbacks yet.
  1. Comments

  2. Tom Foremski
    | #1

    Sounds like a great combination! What types of problems would this solve?

  3. khailey
    | #2

    Hi Tom – good question. I’ve gone into a little more detail on architectures and what problems they solve on the next blog post at http://datavirtualizer.com/docker-and-delphix-architectures/


six − 2 =