{"id":7,"date":"2019-05-04T21:22:36","date_gmt":"2019-05-04T21:22:36","guid":{"rendered":"http:\/\/localhost:8081\/?p=5"},"modified":"2019-05-06T22:19:49","modified_gmt":"2019-05-06T22:19:49","slug":"how-to-wordpress-with-docker","status":"publish","type":"post","link":"https:\/\/blog.nikster.de\/wordpress\/index.php\/2019\/05\/04\/how-to-wordpress-with-docker\/","title":{"rendered":"How to WordPress with docker"},"content":{"rendered":"\n<p style=\"text-align:left\">I&#8217;m experimenting with docker at the moment and built this simple wordpress setup in about 5 minutes.<\/p>\n\n\n\n<p>It consists of:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>a mariadb container<\/li><li>a phpmyadmin container (used for testing the mariabd container and not really required)<\/li><li>the wordpress container itself<\/li><li><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql container: \ndocker run -d --name mariadb-test -e MYSQL_ROOT_PASSWORD=geheim --network test-net -v \/home\/nkalle\/varlibmysql\/:\/var\/lib\/mysql -p 13306:3306 mariadb <\/code><\/pre>\n\n\n\n<p>The above command will spawn a mariabd container from the official image (if you are interested in building your own image, check <a href=\"http:\/\/localhost:8081\/?p=11\">this<\/a> out) with a root password (change it), in a network called test-net, with persistent storage on the local filesystem mapped to \/var\/lib\/mysql (so we won&#8217;t lose all our data when the conatiner is stopped) and a portbinding of 13306 on localhost (mapping 3306, the standard port for mysql).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>phpmyadmin container: docker run -d --name pma -p 8080:80 --network test-net -e PMA_HOST=mariadb-test phpmyadmin\/phpmyadmin <\/code><\/pre>\n\n\n\n<p>Next we&#8217;ll spawn a phpmyadmin container from the official image, in the same virtual net and again with persistent storage. Also we define the mysql host phpmyadmin shall bind to.<\/p>\n\n\n\n<p>Try it with: http:\/\/localhost:8080, after the next step you will see the wordpress database structure here.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wordpress container: docker run -d --name \"wp-test\" --network test-net -v \/home\/nkalle\/wp-html:\/var\/www\/html -p 8081:80 -e WORDPRESS_DB_PASSWORD=geheim -e WORDPRESS_DB_HOST=mariadb-test wordpress<\/code><\/pre>\n\n\n\n<p>Finally we&#8217;ll spawn our wordpress container, referencing our database host and password.<\/p>\n\n\n\n<p>Log in on http:\/\/localhost:8081 and complete the wordpress installation process with a few simple clicks (asking you to choose a language, and a password and you&#8217;re done).<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">How to stop\/start the containers<\/h4>\n\n\n\n<p>When you are done playing around with your new conatiners, you may want to stop them and maybe re-use them again later.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker stop wp-test\n wp-test\n docker stop pma\n pma\n docker stop mariadb-test\n mariadb-test\n docker start mariadb-test\n mariadb-test\n docker start pma\n pma\n docker start wp-test\n wp-test<\/code><\/pre>\n\n\n\n<p>stop the database last and start it first, so you don&#8217;t lose any data.<br><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">A few commands to remember<\/h4>\n\n\n\n<p>When you are working with docker (or some of the above didn&#8217;t went as expected), one will find the following commands to be useful:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker ps<\/code><\/pre>\n\n\n\n<p>shows started containers (ps -a also shows a history of container already closed, exited, etc.)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker image ls<\/code><\/pre>\n\n\n\n<p>shows all docker images on your host<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> docker inspect &lt;imagename\/id><\/code><\/pre>\n\n\n\n<p>shows data about the selected container (including status, network information, etc.)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker logs &lt;imagename\/id><\/code><\/pre>\n\n\n\n<p>show the logs for the selected container<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker exec &lt;options> &lt;command><\/code><\/pre>\n\n\n\n<p>executes command in a running docker instance, e.g.:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker exec -i -t mariadb-test bash<\/code><\/pre>\n\n\n\n<p>this starts a bash in our mariadb-test instance and opens an input stream (-i) that acts like a terminal (-t)<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>This post was largely inspired by reading &#8220;Docker. Das Praxisbuch f\u00fcr Entwickler und Dev-Ops Teams&#8221;<br>https:\/\/www.rheinwerk-verlag.de\/docker_4599\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m experimenting with docker at the moment and built this simple wordpress setup in about 5 minutes. It consists of: a mariadb container a phpmyadmin container (used for testing the mariabd container and not really required) the wordpress container itself The above command will spawn a mariabd container from the official image (if you are &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.nikster.de\/wordpress\/index.php\/2019\/05\/04\/how-to-wordpress-with-docker\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to WordPress with docker&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[3,18,12,4],"class_list":["post-7","post","type-post","status-publish","format-standard","hentry","category-docker","tag-docker","tag-how-to","tag-howto","tag-wordpress","entry"],"_links":{"self":[{"href":"https:\/\/blog.nikster.de\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/7","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.nikster.de\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.nikster.de\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.nikster.de\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.nikster.de\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=7"}],"version-history":[{"count":2,"href":"https:\/\/blog.nikster.de\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/7\/revisions"}],"predecessor-version":[{"id":27,"href":"https:\/\/blog.nikster.de\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/7\/revisions\/27"}],"wp:attachment":[{"href":"https:\/\/blog.nikster.de\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=7"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.nikster.de\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=7"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.nikster.de\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=7"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}