{"id":81,"date":"2019-09-25T07:49:35","date_gmt":"2019-09-25T05:49:35","guid":{"rendered":"https:\/\/blog.simon-frey.eu\/?p=81"},"modified":"2024-01-19T12:52:36","modified_gmt":"2024-01-19T11:52:36","slug":"local-wordpress-plugin-development-with-docker-compose","status":"publish","type":"post","link":"https:\/\/simon-frey.com\/blog\/local-wordpress-plugin-development-with-docker-compose\/","title":{"rendered":"Local WordPress plugin development with docker-compose"},"content":{"rendered":"\n<p>As my WordPress plugin development process was quite flawed (<em>Write code locally =&gt; upload via FTP =&gt; test on server =&gt; repeat<\/em> :&#8217;D) I had to search for a better solution for being able to local develop plugins and test them.<\/p>\n\n\n\n<p>I used this awful process before as I did not want to install all required software for running WordPress (Apache, MySQL, PHP) on my local machine as I like it being clean and only having services running I really need at that certain moment. <\/p>\n\n\n\n<p>The better sysadmins of you would claim that I still could easily start\/stop the services for only having them running when I am developing\u2026but boy that still sounds like a way to big hassle for me.<\/p>\n\n\n\n<p>And as you always do this nowadays: <strong>Docker for the rescue \ud83d\ude09<\/strong><br>After researching and working my way to build a docker-compose file I now can say: This time this approach worked like a charm.<\/p>\n\n\n\n<p>It now only is <code>docker-compose up<\/code> and WordPress is running. I can live edit the files of my plugins, and they are loaded and used instantly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">docker-compose.yml<\/h2>\n\n\n\n<p>I assume you know about docker and docker-compose, if not give <a href=\"https:\/\/docker-curriculum.com\/\">this article<\/a> a read.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>version: '3.3'\nservices:\n   db:\n     image: mysql:5.7\n     volumes:\n       - db_data:\/var\/lib\/mysql\n     restart: always\n     environment:\n       MYSQL_ROOT_PASSWORD: rootpw\n       MYSQL_DATABASE: wordpress\n       MYSQL_USER: wordpress\n       MYSQL_PASSWORD: wordpress\n   wordpress:\n     depends_on:\n       - db\n     image: wordpress:latest\n     ports:\n       - \"8080:80\"\n     restart: always\n     volumes:\n         - ..\/mastodon_wordpress_autopost\/autopost-to-mastodon\/trunk:\/var\/www\/html\/wp-content\/plugins\/autopost-to-mastodon:ro\n     environment:\n       WORDPRESS_DB_HOST: db:3306\n       WORDPRESS_DB_USER: wordpress\n       WORDPRESS_DB_PASSWORD: wordpress\n       WORDPRESS_DB_NAME: wordpress\nvolumes:\n    db_data: {}<\/code><\/pre>\n\n\n\n<p>After executing <code>docker-compose up<\/code> in the directory of the <code>docker-compose.yml<\/code> all the services are started up and you are greeted with a WordPress installer on <code>localhost:8080<\/code> (as I mapped the WordPress port to <code>8080<\/code>).<\/p>\n\n\n\n<p>Click trough the WordPress installer and you got a working instance running.<\/p>\n\n\n\n<p>Via the <code>volumes<\/code> section you can map outside directories into the installation.<br> E.g. The following config maps my local developer directory <code>..\/mastodon_wordpress_autopost\/autopost-to-mastodon\/trunk<\/code> (which I have open in my editor) into the plugins directory of WordPress.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> volumes:\n         - ..\/mastodon_wordpress_autopost\/autopost-to-mastodon\/trunk:\/var\/www\/html\/wp-content\/plugins\/autopost-to-mastodon:ro<\/code><\/pre>\n\n\n\n<p>You can map as many directories as you want. Keep in mind that the path is relative to the location of the <code>docker-compose.yml<\/code><\/p>\n\n\n\n<p>After activating the plugin in the WordPress GUI the plugin is up and running and I can live edit at in my editor. As it is mapped and not copied into the docker container all changes are reflected live.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>Feedback? Questions? Corrections? <a href=\"mailto:wpdocker@simon-frey.eu\">wpdocker@simon-frey.eu<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Supercharge your development flow with installing your development environment in Docker<\/p>\n","protected":false},"author":1,"featured_media":84,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[24],"tags":[31,32,30],"class_list":["post-81","post","type-post","status-publish","format-standard","hentry","category-webdev","tag-docker","tag-docker-compose","tag-wordpress"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Local WordPress plugin development with docker-compose - Blog by Simon Frey<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/simon-frey.com\/blog\/local-wordpress-plugin-development-with-docker-compose\/\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Simon Frey\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Local WordPress plugin development with docker-compose - Blog by Simon Frey","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/simon-frey.com\/blog\/local-wordpress-plugin-development-with-docker-compose\/","twitter_misc":{"Written by":"Simon Frey","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/simon-frey.com\/blog\/local-wordpress-plugin-development-with-docker-compose\/#article","isPartOf":{"@id":"https:\/\/simon-frey.com\/blog\/local-wordpress-plugin-development-with-docker-compose\/"},"author":{"name":"Simon Frey","@id":"https:\/\/simon-frey.com\/blog\/#\/schema\/person\/34753982b648415636ee7a079f3e19a3"},"headline":"Local WordPress plugin development with docker-compose","datePublished":"2019-09-25T05:49:35+00:00","dateModified":"2024-01-19T11:52:36+00:00","mainEntityOfPage":{"@id":"https:\/\/simon-frey.com\/blog\/local-wordpress-plugin-development-with-docker-compose\/"},"wordCount":346,"publisher":{"@id":"https:\/\/simon-frey.com\/blog\/#\/schema\/person\/34753982b648415636ee7a079f3e19a3"},"image":{"@id":"https:\/\/simon-frey.com\/blog\/local-wordpress-plugin-development-with-docker-compose\/#primaryimage"},"thumbnailUrl":"https:\/\/simon-frey.com\/blog\/wp-content\/uploads\/2019\/09\/wordpress_on_docker_for_local_development.jpg","keywords":["docker","docker-compose","wordpress"],"articleSection":["Webdev"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/simon-frey.com\/blog\/local-wordpress-plugin-development-with-docker-compose\/","url":"https:\/\/simon-frey.com\/blog\/local-wordpress-plugin-development-with-docker-compose\/","name":"Local WordPress plugin development with docker-compose - Blog by Simon Frey","isPartOf":{"@id":"https:\/\/simon-frey.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/simon-frey.com\/blog\/local-wordpress-plugin-development-with-docker-compose\/#primaryimage"},"image":{"@id":"https:\/\/simon-frey.com\/blog\/local-wordpress-plugin-development-with-docker-compose\/#primaryimage"},"thumbnailUrl":"https:\/\/simon-frey.com\/blog\/wp-content\/uploads\/2019\/09\/wordpress_on_docker_for_local_development.jpg","datePublished":"2019-09-25T05:49:35+00:00","dateModified":"2024-01-19T11:52:36+00:00","breadcrumb":{"@id":"https:\/\/simon-frey.com\/blog\/local-wordpress-plugin-development-with-docker-compose\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/simon-frey.com\/blog\/local-wordpress-plugin-development-with-docker-compose\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/simon-frey.com\/blog\/local-wordpress-plugin-development-with-docker-compose\/#primaryimage","url":"https:\/\/simon-frey.com\/blog\/wp-content\/uploads\/2019\/09\/wordpress_on_docker_for_local_development.jpg","contentUrl":"https:\/\/simon-frey.com\/blog\/wp-content\/uploads\/2019\/09\/wordpress_on_docker_for_local_development.jpg","width":991,"height":602,"caption":"Wordpress on Docker Whale"},{"@type":"BreadcrumbList","@id":"https:\/\/simon-frey.com\/blog\/local-wordpress-plugin-development-with-docker-compose\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/simon-frey.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Local WordPress plugin development with docker-compose"}]},{"@type":"WebSite","@id":"https:\/\/simon-frey.com\/blog\/#website","url":"https:\/\/simon-frey.com\/blog\/","name":"Blog by Simon Frey","description":"","publisher":{"@id":"https:\/\/simon-frey.com\/blog\/#\/schema\/person\/34753982b648415636ee7a079f3e19a3"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/simon-frey.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/simon-frey.com\/blog\/#\/schema\/person\/34753982b648415636ee7a079f3e19a3","name":"Simon Frey","logo":{"@id":"https:\/\/simon-frey.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/simon-frey.com","https:\/\/www.linkedin.com\/in\/simonfrey\/","https:\/\/x.com\/eu_frey"]}]}},"_links":{"self":[{"href":"https:\/\/simon-frey.com\/blog\/wp-json\/wp\/v2\/posts\/81","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/simon-frey.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/simon-frey.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/simon-frey.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/simon-frey.com\/blog\/wp-json\/wp\/v2\/comments?post=81"}],"version-history":[{"count":2,"href":"https:\/\/simon-frey.com\/blog\/wp-json\/wp\/v2\/posts\/81\/revisions"}],"predecessor-version":[{"id":157,"href":"https:\/\/simon-frey.com\/blog\/wp-json\/wp\/v2\/posts\/81\/revisions\/157"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/simon-frey.com\/blog\/wp-json\/wp\/v2\/media\/84"}],"wp:attachment":[{"href":"https:\/\/simon-frey.com\/blog\/wp-json\/wp\/v2\/media?parent=81"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/simon-frey.com\/blog\/wp-json\/wp\/v2\/categories?post=81"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/simon-frey.com\/blog\/wp-json\/wp\/v2\/tags?post=81"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}