Deploying WordPress in a Docker Container: A Case Study

June 8, 2022

Does your company use WordPress? As the de facto standard for content marketing, it is an incredibly popular piece of open source software. But supporting it can present challenges for engineering departments that have their own software product to work on. 

At Instana we use WordPress for our website and blog (the one you’re reading right now). When we were just getting started we chose to use a managed hosting service. They were able to provide the specific expertise and support that we needed in order to get up and running.  

But as we grew, we ran up against some of the challenges that come with managed hosting. Specifically, we wanted more flexibility and freedom in how we managed deployments, which plugins we could use, and we also wanted to use some tools that required root access to our server. 

To solve those challenges we moved our website to our own self-managed hosting solution. This gave us the flexibility to use the tools we wanted to use while also giving us more control over security, performance and availability. This move also came with new challenges. The new control we had came with new responsibilities.  

 Watch the Monitoring Docker Apps: A WordPress Example Webinar

Hosting WordPress on Docker 

WordPress has relatively lightweight requirements: a PHP web server and a database server. Specifically, the latest version of WordPress (5.9.3 as of writing) requires PHP 7.4 or greater and either MySQL version 5.7 or MariaDB version 10.3 or higher.  

The official WordPress images on Docker Hub come in Apache and PHP-FPM varieties, however the PHP-FPM images lack a web server and so you must configure your own. 

Bitnami publishes WordPress docker images using Apache or a combination of NGINX and PHP-FPM. For performance, security, and ease we opted to use the Bitnami NGINX image for our website.  

With either the official WordPress docker images or the ones from Bitnami, several environment variables are available so that database credentials and other configuration can be provided to WordPress… which brings us to the other requirement: the database. 

Where you host your WordPress database will likely depend on the resources already available to your team. If you wish to host your database in the same Docker environment as the web server, the official MariaDB image works great – just don’t forget to backup your storage volume. 

Alternatively, you may choose to utilize a service like Amazon RDS or IBM Cloud Databases. In this case all you will need to do is provide the correct URL and credentials in your web server environment variables. 

Multiple WordPress installations can share a single MySQL database as long as you change the `DATABASE_PREFIX` environment variable to be unique for each installation.  

Files and storage

Out of the box, WordPress expects you to keep your custom code, plugins, and themes in specific subdirectories of the `wp-content` directory. Everything outside of this directory is WordPress core, and everything inside this directory is your specific WordPress website.  

Because WordPress allows administrators to install plugins from within the dashboard, it is possible to update the actual code of the website while it is live. In order to support this functionality, the `wp-content` directory (or its specific subdirectories) must be mounted as a volume and shared by all containers. 

WordPress developers may also be accustomed to working with shared hosts where small updates can be made by simply uploading new files without waiting for a new Docker image to be built. With the custom code in a volume this is more easily supported, and you will also avoid potential conflicts arising from different plugin versions being available to different containers while all containers necessarily share a single database.  

This might not be a capability you want to support on your team — and we would certainly understand. In this case, we recommend only mounting the `wp-content/uploads` directory as a volume. This directory stores user uploaded images and media files and should be writeable and shared by all container instances. You can set PHP constants in the wp-config.php file to hide the UI areas for installing and updating plugins and themes in the dashboard.

Multiple NGINX/PHP web server containers connected to a single Database container and a single docker volume for media uploads

Hosting with confidence using observability tools 

With our WordPress website now containerized, we are tasked with optimizing, securing, and supporting it. We want to know that our end users are getting a good experience free of errors. We want to know that our server resources are handling our load without excess costs. We want to identify and assess potential security threats. And we want to empower the other members of our team with the data and tools that they need for continuous, data-driven improvements. 

We need the tools to answer these questions. In the past, monitoring our environment may have meant measuring the resource utilization of our hosts and little else. In the modern cloud environment, this is hardly sufficient. Today, we need instrumentation in every layer of our stack. 

Metrics, traces, and logs form the pillars of modern observability. Contextualizing this data using an intelligent observability tool allows us to quickly home in on relevant information while ignoring noise – and in turn reduces MTTR and allows us all move on to more important tasks. 

Watch the Monitoring Docker Apps: A WordPress Example Webinar

Play with Instana’s APM Observability Sandbox

Customer Stories, Product, Remediation, Thought Leadership
Sounds impossible, right? After the initial surge of cloud-native application implementations, many enterprises found that in order to ensure application performance, it’s necessary to add additional hyperscaler resources, especially during peak demands....
Featured, Thought Leadership
Real-Time Observability is a critical monitoring and tracing capability that leads to improved application and systems software health. Why? Because it provides the fastest notification of software and infrastructure issues possible. It...
Developer, Product
The most complex tests and the most challenging methodologies are often most closely aligned with actual production environments. Given this, how can organizations achieve the best results from testing in pre-production? The...

Start your FREE TRIAL today!

Instana, an IBM company, provides an Enterprise Observability Platform with automated application monitoring capabilities to businesses operating complex, modern, cloud-native applications no matter where they reside – on-premises or in public and private clouds, including mobile devices or IBM Z.

Control hybrid modern applications with Instana’s AI-powered discovery of deep contextual dependencies inside hybrid applications. Instana also gives visibility into development pipelines to help enable closed-loop DevOps automation.

This provides actionable feedback needed for clients as they to optimize application performance, enable innovation and mitigate risk, helping Dev+Ops add value and efficiency to software delivery pipelines while meeting their service and business level objectives.

For further information, please visit