{"id":21108,"date":"2015-06-18T13:37:08","date_gmt":"2015-06-18T08:07:08","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=21108"},"modified":"2015-09-17T11:23:59","modified_gmt":"2015-09-17T05:53:59","slug":"wordpress-docker","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/wordpress-docker\/","title":{"rendered":"WordPress Site via Docker using Data Container"},"content":{"rendered":"<p>Docker has gained a lot of attention these days. The main reasons which we know of are that it saves a lot of resources &amp; one can have n number of environments within one server\/machine. It being platform independent, is one more plus point for using docker &amp; hence is one of the fastest growing technologies.<\/p>\n<p>In this blog we will go ahead &amp; setup WordPress (PHP) using docker containers in a very simple way &amp; also make use of <strong>system volumes<\/strong>. Considering the fact that you have installed docker on your machine we would now start to learn about how to setup the WordPress site via docker.<\/p>\n<p><span style=\"text-decoration: underline;\"><strong><span style=\"color: #ff6600; text-decoration: underline;\">There are basically 3 steps to setup the\u00a0WordPress\u00a0site which are as follows<\/span><\/strong>\u00a0<span style=\"color: #ff6600; text-decoration: underline;\">:-<\/span><\/span><\/p>\n<p><strong>1.<\/strong> Use the system volume of your local machine or server for data related container, for example a MySQL container which we will be using here. What we want is even if the container terminates the data remains in stack. In \/var\/lib\/docker you will see volumes. Every time an container is started it goes to this very directory if volumes is defined for the container. Also helps sharing of same file system between two containers.<\/p>\n<p><span style=\"color: #000000;\">Just for your reference this is what we are trying to achieve:-<\/span><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-21168\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/06\/Screenshot-from-2015-06-18-132125.png\" alt=\"Screenshot from 2015-06-18 13:21:25\" width=\"574\" height=\"269\" \/><\/p>\n<p>We will use Linux distribution busy box for this.<strong>\u00a0<span style=\"color: #000000;\">Busy Box<\/span><\/strong>\u00a0is software that provides several stripped-down Unix tools in a single executable file. It runs in a variety of POSIX environments such as Linux.<br \/>\n(source : wiki )<\/p>\n<p>run -&gt;<span style=\"color: #993300;\"><strong> docker run -v \/var\/lib\/mysql &#8211;name=my_data_container -d busybox<\/strong><\/span><\/p>\n<p>This will start a container &amp; create a volume which we will be using later. Also, the thing to remember is that data containers need to be\u00a0started only once. Inspect the container &amp; you will see something like below :-<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-21128\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/06\/Screenshot-from-2015-06-17-175327.png\" alt=\"Screenshot from 2015-06-17 17:53:27\" width=\"842\" height=\"239\" \/><\/p>\n<p>So you can go to \/var\/lib\/docker &amp; there will be entries inside vfs &amp; volumes.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>2.<\/strong> Now, we need to create our MySQL container for WordPress site which will be needing it. For that we can use the MySQL image available in docker registry.<\/p>\n<p class=\"western\">run -&gt;<span style=\"color: #993300;\"><strong> docker run &#8211;name my_mysql -e MYSQL_ROOT_PASSWORD=root &#8211;volumes-from\u00a0<strong>my_data_container\u00a0<\/strong>-d mysql<\/strong><\/span><\/p>\n<p class=\"western\"><strong>-e<\/strong> is an environmental variable which will be used to define the root password in this case. You can add &#8211;volume-from my_data_conatiner if you want the MySQL to use the volume we created earlier.<\/p>\n<p class=\"western\">run -&gt;<span style=\"color: #993300;\"> <strong>docker ps<\/strong><\/span>\u00a0 &amp; you will see something like this :-<\/p>\n<p class=\"western\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-21130\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/06\/Screenshot-from-2015-06-17-180139.png\" alt=\"Screenshot from 2015-06-17 18:01:39\" width=\"755\" height=\"35\" \/><\/p>\n<p>Now, your MySQL container is up &amp; ready.<br \/>\nIf you inspect this container -&gt; <strong><span style=\"color: #993300;\">docker inspect my_mysql<\/span> \u00a0<\/strong>you will see that it is using the data store we created\u00a0earlier.<br \/>\nTo access the MySQL shell you may<br \/>\nrun -&gt;<span style=\"color: #993300;\"><strong> docker <span class=\"keyword\">exec<\/span> -it my_mysql bash<\/strong><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong>3.<\/strong>\u00a0For the WordPress container &amp; linking it to the <span style=\"color: #000000;\"><strong>my_mysql<\/strong><\/span> container do as follows :-<\/p>\n<p class=\"western\">run -&gt; <span style=\"color: #993300;\"><strong>docker run &#8211;name wordpress &#8211;link my_mysql:mysql -p 80:80 -d wordpress<\/strong><\/span><\/p>\n<p>This will pull the WordPress image from docker registry, link the MySQL of WordPress container to the MySQL container that we created in step 2, map port 80 of host machine to port 80 of the WordPress container &amp; run the WordPress container. Now, simply go &amp; hit port 80 of your localhost or your server &amp; the WordPress site should be up &amp; running.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone  wp-image-21153\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/06\/rsz_screenshot_from_2015-06-12_142137.jpg\" alt=\"rsz_screenshot_from_2015-06-12_142137\" width=\"607\" height=\"364\" \/><\/p>\n<p>In my next blog we would be setting up the WordPress image manually rather than pulling it from docker registry which will give us a better overview of docker containers. Also, we would try to integrate it with <strong>ECS<\/strong> which is Amazon Web Services&#8217;s latest addition to its services list so as to support docker.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Docker has gained a lot of attention these days. The main reasons which we know of are that it saves a lot of resources &amp; one can have n number of environments within one server\/machine. It being platform independent, is one more plus point for using docker &amp; hence is one of the fastest growing [&hellip;]<\/p>\n","protected":false},"author":174,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":1},"categories":[1174],"tags":[248,1883],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/21108"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/174"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=21108"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/21108\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=21108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=21108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=21108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}