{"id":595,"date":"2018-03-10T11:33:40","date_gmt":"2018-03-10T11:33:40","guid":{"rendered":"http:\/\/www.45rpmsoftware.com\/wordpress\/?p=595"},"modified":"2018-03-10T12:05:39","modified_gmt":"2018-03-10T12:05:39","slug":"docker-lab-containerising-your-website-part-2-mariadb","status":"publish","type":"post","link":"https:\/\/www.45rpmsoftware.com\/blog\/?p=595","title":{"rendered":"Docker Lab \u2013 Containerising your website, Part 3 (MariaDB)"},"content":{"rendered":"<p>So you&#8217;ve set up containers for Nginx and for PHP &#8211; now you&#8217;d like to have a database. After all the work of the last two labs you&#8217;ll be glad to hear than adding MariaDB to the mix is very simple &#8211; we can get it up and running in minutes.<!--more--><\/p>\n<h2>Why MariaDB?<\/h2>\n<p>I used to use MySQL &#8211; but, I&#8217;ve changed to MariaDB for the following reasons:<\/p>\n<ul>\n<li>Since Oracle bought MySQL, the open development of MySQL has been significantly curtailed. Because of this, MariaDB now enjoys a significantly more vibrant community, and is more open about sharing what changes have been made and why.<\/li>\n<li>MariaDB is quicker than MySQL. Some, rather excitable, metrics show that MariaDB is massively faster than MySQL &#8211; it isn&#8217;t. It&#8217;s a smidgen faster &#8211; reckon on about 5%. But I&#8217;ll take every little boost I can.<\/li>\n<li>MariaDB is significantly compatible with MySQL &#8211; as you might expect since MariaDB was forked from MySQL. This doesn&#8217;t mean that you can just take your MySQL database and load it into MariaDB without any issues &#8211; you&#8217;ll still need to test thoroughly &#8211; but you&#8217;ll experience significantly fewer problems than if you migrated to another DB.<\/li>\n<\/ul>\n<p>It&#8217;s worth noting that whilst you can administer MariaDB using MySQL Workbench I&#8217;d advise against it. \u00a0There are lots of alternative tools available (including a web based admin package that you&#8217;ll install at the end of this tutorial), but I like Navicat Premium Essentials &#8211; which is not free, but which is worth every penny.<\/p>\n<p>As before, These instructions assume that you have followed the steps in the previous instalment (<a href=\"http:\/\/www.45rpmsoftware.com\/wordpress\/?p=590\">Docker Lab \u2013 Containerising your website, Part 2<\/a>)<\/p>\n<h2>Configuring your Containers.<\/h2>\n<p>Yet again, it will come as no surprise that, in order to install PHP, we need to edit the docker-compose.yml file. It will be necessary to stop Docker (just in case you left it running from the last session). You may remember that you can edit the docker-compose.yml file while Docker is still running &#8211; but the changes won&#8217;t take effect until Docker is restarted. I shan&#8217;t tell you how to stop the containers. You can look that up for yourself in Part 2.<\/p>\n<p>Edit docker-compose.yml to add the maria-db container. I added it just below services and before nginx. Replace &lt;Your Root Password Goes Here&gt; with a password of your choice. Make it complicated &#8211; and remember that you probably aren&#8217;t going to have to type it all that often, so it doesn&#8217;t need to be convenient for your fingers. I generally use a UUID &#8211; something like this &#8216;1e1fdb9c-6ba5-48ea-9640-7801eed2022e&#8217;.<\/p>\n<pre>maria-db:\r\n image: 'bitnami\/mariadb:latest'\r\n networks:\r\n  - app-tier\r\n environment:\r\n  - MARIADB_ROOT_PASSWORD=&lt;Your Root Password Goes Here&gt;\r\n volumes:\r\n  - .\/db-data:\/bitnami<\/pre>\n<h3>Generating a UUID.<\/h3>\n<p>If you do want to use a UUID for your password then you can generate one using the following command:<\/p>\n<pre>cat \/proc\/sys\/kernel\/random\/uuid<\/pre>\n<h3>Starting Docker<\/h3>\n<p>Now start Docker, giving it a little while to start up and configure MariaDB before moving on to the next step:<\/p>\n<pre>cd ~\/lemp-compose \r\ndocker-compose up --remove-orphans -d<\/pre>\n<h2>Testing your MariaDB install<\/h2>\n<p>A useful online tool for administering your database and also for testing that MariaDB has been installed correctly is phpminiadmin.php &#8211; in fact this will exercise every part of your set up.<\/p>\n<p>Place the phpminiadmin.php into your site directory as follows:<\/p>\n<pre>cd ~\/lemp-compose\/public\/&lt;your website name&gt;\/htdocs\r\nwget https:\/\/raw.github.com\/osalabs\/phpminiadmin\/master\/phpminiadmin.php<\/pre>\n<p>Browse to your website URL &#8211; in this example, http:\/\/&lt;your domain name&gt;\/phpminiadmin.php, and you&#8217;ll see the phpminiadmin page. Click &#8220;advanced settings&#8221; and log in as follows:<\/p>\n<p><strong>Username:<\/strong> <em>root<\/em><\/p>\n<p><strong>Hostname:<\/strong> <em>maria-db<\/em><\/p>\n<p><strong>Password:<\/strong> whatever you specified in the Docker Compose file.<\/p>\n<p>You will now have access to the phpMiniAdmin database management interface. You can use this interface to create databases and tables and execute SQL queries on your MariaDB database server.<\/p>\n<p>If that all worked then next time we&#8217;ll add certificates. If it didn&#8217;t work, go back and check your working.<\/p>\n<h2>Note!<\/h2>\n<p>If you want to connect to this MariaDB instance from your desktop computer using a tool like Navicat Essentials, you need the following setup.<\/p>\n<p>Click the SSH tab, check the &#8216;Use SSH tunnel&#8217; checkbox and fill in the details that you use to SSH into the server.<\/p>\n<p>Next click on the General tab and fill in the User Name as &#8216;root&#8217; and the password as\u00a0whatever you specified in the Docker Compose file. \u00a0The Host Name \/ IP Address needs to be retrieved from Docker with the following command:<\/p>\n<pre>docker inspect &lt;containerID&gt; | grep \\\"IPAddress\\\"<\/pre>\n<p>Get the Container ID using docker ps, as previously. \u00a0Note that the IP Address may change periodically &#8211; so if you can&#8217;t connect for whatever reason, check this first.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So you&#8217;ve set up containers for Nginx and for PHP &#8211; now you&#8217;d like to have a database. After all the work of the last two labs you&#8217;ll be glad to hear than adding MariaDB to the mix is very simple &#8211; we can get it up and running in minutes.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[15,18,28,5],"tags":[],"_links":{"self":[{"href":"https:\/\/www.45rpmsoftware.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/595"}],"collection":[{"href":"https:\/\/www.45rpmsoftware.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.45rpmsoftware.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.45rpmsoftware.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.45rpmsoftware.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=595"}],"version-history":[{"count":0,"href":"https:\/\/www.45rpmsoftware.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/595\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.45rpmsoftware.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=595"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.45rpmsoftware.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=595"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.45rpmsoftware.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=595"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}