{"id":3159,"date":"2019-10-22T22:56:13","date_gmt":"2019-10-23T03:56:13","guid":{"rendered":"http:\/\/osric.com\/chris\/accidental-developer\/?p=3159"},"modified":"2019-10-27T18:43:29","modified_gmt":"2019-10-27T23:43:29","slug":"running-wordpress-on-docker","status":"publish","type":"post","link":"https:\/\/osric.com\/chris\/accidental-developer\/2019\/10\/running-wordpress-on-docker\/","title":{"rendered":"Running WordPress on Docker"},"content":{"rendered":"<p>Similar to the previous post, <a href=\"https:\/\/osric.com\/chris\/accidental-developer\/2019\/10\/running-joomla-on-docker\/\">Running Joomla on Docker<\/a>, I was interested in spinning up a temporary WordPress installation so that I could target it with various scanning and reconnaissance tools. There is an official WordPress Docker image at <a href=\"https:\/\/hub.docker.com\/_\/wordpress\/\">https:\/\/hub.docker.com\/_\/wordpress\/<\/a>.<\/p>\n<p>The steps were more-or-less the same. Note that if you followed the steps in the previous post, you will likely want to stop and remove the existing MySQL container before attempting to start a new one with the same name:<\/p>\n<pre><code>docker stop some-mysql\r\ndocker rm some-mysql<\/code><\/pre>\n<p><strong>Start the MySQL Docker container:<\/strong><\/p>\n<pre><code>docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=passW0rd -e MYSQL_DATABASE=wordpress -e MYSQL_USER=wordpress -e MYSQL_PASSWORD=wpP455 -d mysql:5<\/code><\/pre>\n<p><strong>Start the WordPress Docker container:<\/strong><\/p>\n<pre><code>docker run --name some-wordpress --link some-mysql:mysql -e WORDPRESS_DB_HOST=172.17.0.2 -e WORDPRESS_DB_USER=wordpress -e WORDPRESS_DB_PASSWORD=wpP455 -e WORDPRESS_DB_NAME=wordpress -p 8080:80 -d wordpress<\/code><\/pre>\n<p>I was then able to visit http:\/\/localhost:8080 and complete the web-based setup tasks.<\/p>\n<p>Note that the MySQL container, as launched, does not have any shared volumes. Everything stored there is ephemeral and will be lost if the container is removed. To my surprise, however, the content survived stopping and restarting the container. The volumes for each container are located in the following directory:<\/p>\n<pre><code>\/var\/lib\/docker\/volumes\/<\/code><\/pre>\n<p>Using <code>docker inspect some-wordpress<\/code> I could see that there was a mounted volume at:<\/p>\n<pre><code>\/var\/lib\/docker\/volumes\/be3d54591da609e911a1ec3f0615a564990b37da184a67fab0ac0e75cc711c7f\/_data<\/code><\/pre>\n<p>Indeed, the usual WordPress files, such as <code>wp-config.php<\/code>, were located there.<\/p>\n<p>I did the same for the MySQL container and found the <code>.frm<\/code> and <code>.ibd<\/code> files for each of the tables in the WordPress database.<\/p>\n<p>These files persist when the container is stopped, and persist even when the container is removed! In fact, when I removed all containers, I discovered there were still 22 volumes in <code>\/var\/lib\/docker\/volumes<\/code> from previous container projects and experiments.<\/p>\n<p>The command to view these volumes is:<\/p>\n<pre><code>docker volume ls<\/code><\/pre>\n<p>To remove unused volumes, use:<\/p>\n<pre><code>docker volume prune<\/code><\/pre>\n<p>Container volumes are not as ephemeral as I originally thought!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post provides instructions on how to quickly launch a temporary WordPress installation using Docker containers. Note that the configuration would provide an installation for demonstration purposes only, and should be modified to insure data persistence if the containers are to be used in production.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[451,90],"tags":[449,359],"class_list":["post-3159","post","type-post","status-publish","format-standard","hentry","category-docker","category-wordpress","tag-docker","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/3159","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/comments?post=3159"}],"version-history":[{"count":3,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/3159\/revisions"}],"predecessor-version":[{"id":3168,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/3159\/revisions\/3168"}],"wp:attachment":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/media?parent=3159"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/categories?post=3159"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/tags?post=3159"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}