{"id":6847,"date":"2017-02-16T09:00:18","date_gmt":"2017-02-16T08:00:18","guid":{"rendered":"https:\/\/anexia.com\/stagingblog\/?p=6847"},"modified":"2022-04-21T14:39:06","modified_gmt":"2022-04-21T12:39:06","slug":"simplified-wordpress-development-with-docker-compose","status":"publish","type":"post","link":"https:\/\/anexia.com\/blog\/en\/simplified-wordpress-development-with-docker-compose\/","title":{"rendered":"Simplified WordPress Development with Docker Compose"},"content":{"rendered":"<p>Development environments are essential in order to bring new software to life. Each technology has a specific set of tools that can be used to create such an environment, and so does <a href=\"https:\/\/anexia.com\/en\/software-development\/web-development\/\">web development<\/a>. In the early days, we used web server solution stacks such as <a href=\"https:\/\/www.apachefriends.org\/de\/index.html\" target=\"_blank\" rel=\"noopener\">XAMPP<\/a> or a virtual machine, where everything was installed manually. In the best case those virtual machines could be exported as a template. By applying custom scripts on these templates, the automatic installation of specific packages was possible. To make our lives easier, we used <a href=\"https:\/\/www.vagrantup.com\/\" target=\"_blank\" rel=\"noopener\">Vagrant<\/a> for this, which made it comfortable to share the development environment for a specific project to all the developers involved. But it takes quite some time to create the scripts and also the runtime and the memory usage are limited (because this system is using <a href=\"https:\/\/www.virtualbox.org\/\" target=\"_blank\" rel=\"noopener\">VirtualBox<\/a>). Also it is time-consuming to create multiple instances of the boxes and connect services between them. But there is a great solution to it: This is where <a href=\"https:\/\/www.docker.com\/\" target=\"_blank\" rel=\"noopener\">Docker<\/a> comes into play.<\/p>\n<p>By using Docker the scripts for creating the environments are easier to read and maintain, and it gives you the possibility to work on docker images created by previous scripts (core images can be created and the docker files are lighter). The final piece in this puzzle is <a href=\"https:\/\/docs.docker.com\/compose\/\" target=\"_blank\" rel=\"noopener\">Docker Compose<\/a>. This package allows the creation of a configuration file where all the commands that usually run in the console can be written in a more readable and expandable way. It also gives you the possibility to connect containers. This is how we can create components that are responsible for only one purpose: web server, database, emails and so on.<\/p>\n<p>Using this power we can establish an easier workflow for WordPress projects, e.g. developing a plugin, a theme or even an entire new project based on WordPess. For this, we are going to use WPDC (WordPress Docker Compose): You can find it here in my <a href=\"https:\/\/github.com\/nezhar\/wordpress-docker-compose\" target=\"_blank\" rel=\"noopener\">GitHub directory<\/a>.<\/p>\n<h2>Developing a full project<\/h2>\n<p>Here we have two scenarios. Either starting a fresh project or continuing from an existing source. The Docker Compose configuration from WPDC will cover both situations.<\/p>\n<h3>Starting a new project<\/h3>\n<p>When developing an entire project that is based on WordPress, the access to the entire <strong>wp-content<\/strong> directory is required, as this is the place where the work of a developer goes (themes, plugins, translations, etc.). The default configuration for the volumes (.\/wp-app:\/var\/www\/html) will map all the files from the WordPress container, located inside the \/var\/www\/html directory to the <strong>wp-app<\/strong> directory on the disk in the current working directory. This also means access to the core of WordPress and configuration files. This gives a huge advantage in performing updates manually and keeping them in a version control system, to assure that components are still working. There is also the option to directly map the wp-content directory (.\/wp-content:\/var\/www\/html\/wp-content). By using this approach, the WordPress core will not get into the version control system, but it\u2019s risky to end up with a broken project if the theme or one of the plugins is not compatible with the new core of WordPress. This wont be an issue for an ongoing project, as it should rely on the latest core anyway, but if there is a longer pause on the project, trouble may occur. By having control over the core updates, code can be better managed and tested.<\/p>\n<p>The docker-compose.yml file is using the official WordPress and MySQL images in the latest versions. It can be also reconfigured in order to use something that is closer to the actual server requirements of the project. The current <strong>wordpress:latest<\/strong> is using WordPress on PHP 5.6 with an Apache server, but by simply changing the tag <strong>latest<\/strong> with<strong> php7.0-apache<\/strong> it can use another docker image which provides PHP 7.0. The same applies for the database images. There is even an option to use the MariaDB images instead of MySQL when required.<\/p>\n<p>After deciding with the team how the volumes should be configured and which images to use, it\u2019s time to start the containers. Open a terminal and go to the directory of the docker-compose.yml file and run:<\/p>\n<pre class=\"lang:sh decode:true\">docker-compose up<\/pre>\n<p>This will create two new folders in the working directory. One where the WordPress app is located (wp-app) and one for the database (wp-data) which will be empty for now.<\/p>\n<p>For convenience, it\u2019s recommended to define a host name in the <strong>\/etc\/hosts<\/strong>, that will map to 127.0.0.1 (this is by default configured on the docker-compose.yml) instead of directly using the IP address in the browser. After this is done, the page can be opened in the browser to finish the WordPress installation.<br \/>\nFrom now on, the development environment is set and everybody can start configuring and coding the WordPress project.<br \/>\nFrom time to time, one of the team members should consider creating a set of test data in the database, which all developers may have access to. There is a small shell script called export.sh. Running this in the console will create a dump from the database container into the wp-data directory. This allows having a test SQL dump in the version control system.<br \/>\nIn order to have the database in the same state as the dump, it\u2019s enough to remove the containers and recreate them, by using:<\/p>\n<pre class=\"lang:sh decode:true\">docker-compose down\r\ndocker-compose up<\/pre>\n<p>The <strong>wp-data<\/strong> directory will be used when creating the container for the database, and will load all the SQL files available in it (make sure to have only one dump file).<\/p>\n<h3>Continuing a project from an existing source<\/h3>\n<p>This case occurs when a full WordPress project (including the core) and a SQL dump are available. Create a wp-app directory and copy all the WordPress files into it. After that create another directory called wp-data (this is based on the default configuration) and place the database dump in it. Make sure to add proper image tags to the docker-compose.yml file when other PHP or MySQL versions are required. After doing so, the development environment can be started:<\/p>\n<pre class=\"lang:sh decode:true\">docker-compose up<\/pre>\n<p>Now a host entry is required (as described above) and WordPress has to use this new host. The easiest way to achieve this is by defining two constants in the <strong>wp-config.php<\/strong> file:<\/p>\n<pre class=\"lang:php decode:true\">define('WP_HOME','http:\/\/wp-app.local');\r\ndefine('WP_SITEURL','http:\/\/wp-app.local');<\/pre>\n<h2>Developing a theme or plugin<\/h2>\n<p>By applying the same principle, it is possible developing only specific components for WordPress, like themes and plugins. All it needs is a proper configuration of Volumes in the docker-compose.yml file.<\/p>\n<p><strong>For theme development:<\/strong><\/p>\n<pre class=\"lang:sh decode:true\">volumes:\r\n- .\/theme-name\/trunk\/:\/var\/www\/html\/wp-content\/themes\/theme-name<\/pre>\n<p><strong>For plugin development:<\/strong><\/p>\n<pre class=\"lang:sh decode:true \">volumes:\r\n- .\/plugin-name\/trunk\/:\/var\/www\/html\/wp-content\/plugins\/plugin-name<\/pre>\n<p>Creating or continuing the development of a theme or plugin works the same way as for a project.<\/p>\n<h2>Conclusion<\/h2>\n<p>It may require some time to install Docker, Docker Compose and to get used with the commands of Docker that bring the development environment to life. But it won\u2019t take too long and the benefit is huge. This principle can be applied on all WordPress projects, and each team member can benefit from it, and save time for the development process. We are definitely saving a lot of time and unnecessary frustration!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Harald explains, how a developement environment for WordPress is created with Docker Compose: for new and existing projects as well as for plugins\/themes.<\/p>\n","protected":false},"author":13,"featured_media":484,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1135,2211],"tags":[1721,1723,1594],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Simplified WordPress Development with Docker Compose - ANEXIA Blog<\/title>\n<meta name=\"description\" content=\"Harald explains, how a developement environment for WordPress is created with Docker Compose: for new and existing projects as well as for plugins\/themes.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/anexia.com\/blog\/en\/simplified-wordpress-development-with-docker-compose\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Simplified WordPress Development with Docker Compose - ANEXIA Blog\" \/>\n<meta property=\"og:description\" content=\"Harald explains, how a developement environment for WordPress is created with Docker Compose: for new and existing projects as well as for plugins\/themes.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/anexia.com\/blog\/en\/simplified-wordpress-development-with-docker-compose\/\" \/>\n<meta property=\"og:site_name\" content=\"ANEXIA Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/anexiagmbh\/\" \/>\n<meta property=\"article:published_time\" content=\"2017-02-16T08:00:18+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-04-21T12:39:06+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/anexia.com\/blog\/wp-content\/uploads\/2015\/01\/Harald-N_web.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1600\" \/>\n\t<meta property=\"og:image:height\" content=\"1067\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Harald Nezbeda\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@_ANEXIA\" \/>\n<meta name=\"twitter:site\" content=\"@_ANEXIA\" \/>\n<meta name=\"twitter:label1\" content=\"Verfasst von\" \/>\n\t<meta name=\"twitter:data1\" content=\"Harald Nezbeda\" \/>\n\t<meta name=\"twitter:label2\" content=\"Gesch\u00e4tzte Lesezeit\" \/>\n\t<meta name=\"twitter:data2\" content=\"6\u00a0Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/anexia.com\/blog\/en\/simplified-wordpress-development-with-docker-compose\/\",\"url\":\"https:\/\/anexia.com\/blog\/en\/simplified-wordpress-development-with-docker-compose\/\",\"name\":\"Simplified WordPress Development with Docker Compose - ANEXIA Blog\",\"isPartOf\":{\"@id\":\"https:\/\/anexia.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/anexia.com\/blog\/en\/simplified-wordpress-development-with-docker-compose\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/anexia.com\/blog\/en\/simplified-wordpress-development-with-docker-compose\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/anexia.com\/blog\/wp-content\/uploads\/2015\/01\/Harald-N_web.jpg\",\"datePublished\":\"2017-02-16T08:00:18+00:00\",\"dateModified\":\"2022-04-21T12:39:06+00:00\",\"author\":{\"@id\":\"https:\/\/anexia.com\/blog\/#\/schema\/person\/9196661829f9337366e2f283b30199e3\"},\"description\":\"Harald explains, how a developement environment for WordPress is created with Docker Compose: for new and existing projects as well as for plugins\/themes.\",\"breadcrumb\":{\"@id\":\"https:\/\/anexia.com\/blog\/en\/simplified-wordpress-development-with-docker-compose\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/anexia.com\/blog\/en\/simplified-wordpress-development-with-docker-compose\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"https:\/\/anexia.com\/blog\/en\/simplified-wordpress-development-with-docker-compose\/#primaryimage\",\"url\":\"https:\/\/anexia.com\/blog\/wp-content\/uploads\/2015\/01\/Harald-N_web.jpg\",\"contentUrl\":\"https:\/\/anexia.com\/blog\/wp-content\/uploads\/2015\/01\/Harald-N_web.jpg\",\"width\":1600,\"height\":1067,\"caption\":\"Python Harald Nezbeda\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/anexia.com\/blog\/en\/simplified-wordpress-development-with-docker-compose\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/anexia.com\/blog\/de\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Simplified WordPress Development with Docker Compose\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/anexia.com\/blog\/#website\",\"url\":\"https:\/\/anexia.com\/blog\/\",\"name\":\"ANEXIA Blog\",\"description\":\"[:de] ANEXIA Blog - Technischen Themen, Anexia News und Insights [:]\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/anexia.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"de\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/anexia.com\/blog\/#\/schema\/person\/9196661829f9337366e2f283b30199e3\",\"name\":\"Harald Nezbeda\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"https:\/\/anexia.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f433475ef86738781d677056909b37c3?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f433475ef86738781d677056909b37c3?s=96&d=mm&r=g\",\"caption\":\"Harald Nezbeda\"},\"url\":\"https:\/\/anexia.com\/blog\/author\/hn\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Simplified WordPress Development with Docker Compose - ANEXIA Blog","description":"Harald explains, how a developement environment for WordPress is created with Docker Compose: for new and existing projects as well as for plugins\/themes.","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:\/\/anexia.com\/blog\/en\/simplified-wordpress-development-with-docker-compose\/","og_locale":"de_DE","og_type":"article","og_title":"Simplified WordPress Development with Docker Compose - ANEXIA Blog","og_description":"Harald explains, how a developement environment for WordPress is created with Docker Compose: for new and existing projects as well as for plugins\/themes.","og_url":"https:\/\/anexia.com\/blog\/en\/simplified-wordpress-development-with-docker-compose\/","og_site_name":"ANEXIA Blog","article_publisher":"https:\/\/www.facebook.com\/anexiagmbh\/","article_published_time":"2017-02-16T08:00:18+00:00","article_modified_time":"2022-04-21T12:39:06+00:00","og_image":[{"width":1600,"height":1067,"url":"https:\/\/anexia.com\/blog\/wp-content\/uploads\/2015\/01\/Harald-N_web.jpg","type":"image\/jpeg"}],"author":"Harald Nezbeda","twitter_card":"summary_large_image","twitter_creator":"@_ANEXIA","twitter_site":"@_ANEXIA","twitter_misc":{"Verfasst von":"Harald Nezbeda","Gesch\u00e4tzte Lesezeit":"6\u00a0Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/anexia.com\/blog\/en\/simplified-wordpress-development-with-docker-compose\/","url":"https:\/\/anexia.com\/blog\/en\/simplified-wordpress-development-with-docker-compose\/","name":"Simplified WordPress Development with Docker Compose - ANEXIA Blog","isPartOf":{"@id":"https:\/\/anexia.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/anexia.com\/blog\/en\/simplified-wordpress-development-with-docker-compose\/#primaryimage"},"image":{"@id":"https:\/\/anexia.com\/blog\/en\/simplified-wordpress-development-with-docker-compose\/#primaryimage"},"thumbnailUrl":"https:\/\/anexia.com\/blog\/wp-content\/uploads\/2015\/01\/Harald-N_web.jpg","datePublished":"2017-02-16T08:00:18+00:00","dateModified":"2022-04-21T12:39:06+00:00","author":{"@id":"https:\/\/anexia.com\/blog\/#\/schema\/person\/9196661829f9337366e2f283b30199e3"},"description":"Harald explains, how a developement environment for WordPress is created with Docker Compose: for new and existing projects as well as for plugins\/themes.","breadcrumb":{"@id":"https:\/\/anexia.com\/blog\/en\/simplified-wordpress-development-with-docker-compose\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/anexia.com\/blog\/en\/simplified-wordpress-development-with-docker-compose\/"]}]},{"@type":"ImageObject","inLanguage":"de","@id":"https:\/\/anexia.com\/blog\/en\/simplified-wordpress-development-with-docker-compose\/#primaryimage","url":"https:\/\/anexia.com\/blog\/wp-content\/uploads\/2015\/01\/Harald-N_web.jpg","contentUrl":"https:\/\/anexia.com\/blog\/wp-content\/uploads\/2015\/01\/Harald-N_web.jpg","width":1600,"height":1067,"caption":"Python Harald Nezbeda"},{"@type":"BreadcrumbList","@id":"https:\/\/anexia.com\/blog\/en\/simplified-wordpress-development-with-docker-compose\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/anexia.com\/blog\/de\/"},{"@type":"ListItem","position":2,"name":"Simplified WordPress Development with Docker Compose"}]},{"@type":"WebSite","@id":"https:\/\/anexia.com\/blog\/#website","url":"https:\/\/anexia.com\/blog\/","name":"ANEXIA Blog","description":"[:de] ANEXIA Blog - Technischen Themen, Anexia News und Insights [:]","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/anexia.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"de"},{"@type":"Person","@id":"https:\/\/anexia.com\/blog\/#\/schema\/person\/9196661829f9337366e2f283b30199e3","name":"Harald Nezbeda","image":{"@type":"ImageObject","inLanguage":"de","@id":"https:\/\/anexia.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/f433475ef86738781d677056909b37c3?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f433475ef86738781d677056909b37c3?s=96&d=mm&r=g","caption":"Harald Nezbeda"},"url":"https:\/\/anexia.com\/blog\/author\/hn\/"}]}},"lang":"en","translations":{"en":6847,"de":2326},"amp_enabled":true,"pll_sync_post":[],"_links":{"self":[{"href":"https:\/\/anexia.com\/blog\/wp-json\/wp\/v2\/posts\/6847"}],"collection":[{"href":"https:\/\/anexia.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/anexia.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/anexia.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/anexia.com\/blog\/wp-json\/wp\/v2\/comments?post=6847"}],"version-history":[{"count":2,"href":"https:\/\/anexia.com\/blog\/wp-json\/wp\/v2\/posts\/6847\/revisions"}],"predecessor-version":[{"id":7572,"href":"https:\/\/anexia.com\/blog\/wp-json\/wp\/v2\/posts\/6847\/revisions\/7572"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/anexia.com\/blog\/wp-json\/wp\/v2\/media\/484"}],"wp:attachment":[{"href":"https:\/\/anexia.com\/blog\/wp-json\/wp\/v2\/media?parent=6847"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/anexia.com\/blog\/wp-json\/wp\/v2\/categories?post=6847"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/anexia.com\/blog\/wp-json\/wp\/v2\/tags?post=6847"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}