Containerize your database volume with Tutum MySQL Images

Nowadays, there are more and more people starting to use docker to containerize their applications, and MySQL is the most popular one.It is as simple as one command line to create and start your own database:

docker run -d –P tutum/mysql

However if you decide to replace MySQL with MariaDB in the future, data migration will be painful to perform. Tutum MySQL/MariaDB images help solve this problem.

Here is a simple example:

1. Create a volume container that holds database data

docker run -d -v /var/lib/mysql –name db_vol -p 22:22 tutum/ubuntu:trusty

Note: you can change the name of the volume container, which will be used in the next step. The volume path (/var/lib/mysql) should not be changed.

2. Create a MySQL container and write data to the volume container:

docker run -d –volumes-from db_vol -p 3306:3306 tutum/mysql:5.5

Note: –volumes-from should use the name of the volume container.

Here’s the log view of the MySQL container:

image1

Since there is no data inside the volume, Tutum MySQL image will help you initialize the database and create an admin user with a random password. If you want to use a preset password, add ‘-e MYSQL_PASS=<yourpass>’ in the run command above.

Let’s create a new database name ‘hello_tutum’:

image2

3. Now stop the container and all the data is preserved in our volume container.

docker stop 7aa5dcaf8e41

Note: change the container id to the one you got in step 2.

4. Create a MariaDB container with the same volume container:

docker run -d –volumes-from db_vol -p 3306:3306 tutum/mariadb:5.5

Here is the log of MariaDB:

image3

Since we have created a database in the volume container, MariaDB will use the volume directly.

Let’s check what’s in the database using the same credentials we used in the MySQL container:

image4

Here you can see that the version of database server changed to MariaDB, while the data was preserved.

Enjoy !

Tagged with: , , ,
Posted in Images, Tutorial
7 comments on “Containerize your database volume with Tutum MySQL Images
  1. […] volume的介绍,可以参考一下:https://blog.tutum.co/2014/05/27/containerize-your-database-volume-with-tutum-mysql-images/ […]

  2. The second stage, which is a loww pressure section, will
    include the entire reheater, thhe interconnecting piping, headers in this section, all the
    vents, and all drains. Several cleaning methods are available for
    different types of carpets. The mechanisms of steam soot blower erosion of heat transfer tubes can be a single factor or
    multiple factors acting individually or in unison.

  3. xxx says:

    Thankfulness to my father who informed me concerning this weblog, this webpage
    is really awesome.

Leave a Comment

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

Categories
%d bloggers like this: