spinah logo

Setting Up WordPress with Docker Containers: A Step-by-Step Guide

| April 18, 2023

Setting up a wordpress on a docker container

When it comes to producing high-quality products, running WordPress websites often involves utilizing various configurations and software packages. 

You may have wondered if there is a simpler way to work on these kinds of projects on your own PC without having to run so many different programs. For example, you may have considered using an online service.

Docker is a tool that, thankfully, makes it possible to install WordPress faster and more easily. Docker is much more than just a simple virtual machine; it also offers containers, which can be used for the development of WordPress websites as well as other applications and technologies. Docker makes it easier to get applications ready for distribution on different platforms, thus speeding up your workflow.

In this piece, we’ll take a look at exactly what containers are and how using them impacts the development process. After that, we will discuss how to configure a container for WordPress development on a local server and how to get it ready for production. Let’s begin!

What Are Docker Containers?

Containers are a way of packaging software into isolated units that contain everything necessary to run the application. They take up less space and require fewer resources, as they don’t need their own operating system. Instead, they can use one that’s already installed on the host machine.

Containers make it easy to deploy applications, such as WordPress, across different platforms, as all the code and files are self-contained. They also make it much easier to debug applications because all the necessary parts are included in the container.

Docker is not the same as traditional virtual machines, even though it is a form of virtualization (VMs). Containerized development makes better use of available space than traditional methods, such as virtual machines (VMs), which add the userspace of the host operating system to the userspace of each program.

The best thing about Docker is that it will work the same way regardless of the operating system you are using. In addition, you can run a large number of Docker containers on a single machine, with each running a single service, even if that machine would otherwise struggle to handle an equivalent number of virtual machines (VMs). 

You also won’t have to worry about any of the problems that can occasionally be caused by developing software stacks on a local level. In the world of software installations and applications, this problem is commonly referred to as the “but it works on my system” paradox.

WordPress Docker: How to Get Started With It

Download and Run Docker 

Docker has a lot of different products that, when used together, make a very useful set of tools for software developers. You can get started using the Docker Engine by downloading the free version of the Community Edition:

In order to download the engine, you will first need to make a Docker account for yourself. Then, read the information that Docker provides you under the heading “Get started.” Eight distinct versions of Docker available for you to select from. Download Docker Desktop for Windows and make sure your Windows system meets the following requirements if you want to follow along with this demo:

In order to download the engine, you will first need to sign in to your Docker account. You will also need to make sure that your computer has a terminal application installed and ready to use.

Once your system has been restored to full functionality, open the command line. If you don’t want to install another program, you can simply search for Powershell on Windows. Next, enter ‘docker ps’. If Docker is properly installed, you should see the Docker menu with a whale icon on your desktop’s status bar.

Set up a Container With a WordPress Environment Variables

There are two ways to approach this step: either make a container and arrange each component one at a time, or do it all at once. Let’s take a look at the second option as it makes sense to do so.

We’ll use a program called Docker Compose, which allows you to configure all of the services your container should have all at once. Compose comes pre-installed with Docker Desktop for Mac or Windows:

You must use Terminal to run the installation commands if you’re using Linux. Just remember that the Docker Engine is a requirement for Compose. To work on any WordPress development, you must have both installed to make up the entire environment.

All of the services of your application are configured by Compose using YAML files. This method of presenting data serialization is user-friendly and compatible with all computer languages. In this instance, the YAML file will configure the essential data for the WordPress database service.

Outline the Project

Start working on your first WordPress development project after installing Compose and Docker Engine. You must use the “make directory” single command to establish a fresh, empty project directory:

mkdir new_wordpress/m 

The current directory will serve as the development context and will only include the things you actually need, like your docker-compose.yml file. In the subsequent step, we’ll generate the configuration file. Next, use the single command below to navigate to your new directory:

cd new_wordpress/

You are now in the directory for your new project and are prepared to start working.

Make a YAML Docker-compose file

You must now make a fresh docker-compose.yaml file. Your new WordPress installation and the required MySQL database container will be created as a result. Your file will include all of the essential hostnames, db container, ports, and root passwords for both WordPress and your database.

Your YAML file should resemble the following:

It’s important to note that Docker volumes include persistent data. To properly understand volumes, you may wish to consult the volume documentation.

Create the Project Directory

After configuring the YAML file, you must run the script to fetch all the necessary images and set up your WordPress project. You should issue the following command from within the root directory of the project:

Currently, Docker should be “pulling” in the MySQL and WordPress images, as you can see.

It’s important to note that the Docker Hub image pages for the MySQL and WordPress application containers include a wealth of useful information. Consider these to be your one-stop reference guide for the container image’s useful commands. It would be wise to save them for later use.

Access WordPress Installation Page

You must use the port specified in your YAML root file rather than the standard WordPress /install.php script. 

The final step is to instruct Docker to launch your container. Use the following command within the root folder containing your docker-compose.yml to accomplish that;

Now, you can sit back and wait for Docker to install all the services you listed in your docker-compose.yml config file. Depending on the speed of your internet connection, this could take some time.

Once everything is set up, you can use any browser to access your WordPress site by simply inputting the ports you previously configured. This would be in this instance.

After Docker has had time to fully load and initialize the official images, you can go to WordPress in a browser to finish the normal installation steps.

It’s advised that you “shut down and clean up” as soon as the installation is complete. The Docker “down” command can be used to accomplish this. The WordPress database is kept while the containers are stopped and removed. 

You are now prepared to begin developing WordPress locally using Docker.

Watch for more guide: https://youtu.be/pYhLEV-sRpY 

Why Utilize Docker to Build a Local WordPress Environment

Most of the time, you have to install the whole environment at once to make a local WordPress development website. Once you’ve done that, unless you wish to remove the existing components and add new ones, you’re stuck with the environment variable you’ve selected. 

For example, installing NGINX on your computer along with an Apache server can be a huge pain. To replicate your production environments, you may need to swap out components.

We now come to Docker, a program that lets you create separate “containers” that contain full development environments. Assembling a virtual machine (VM) without an operating system comes to mind. 

These containers offer practically all of the same advantages as VMs without adding extra weight to your system. This effectively means that you can configure different environments on a standard machine.

And if that weren’t enough, you can easily turn on and off containers. Your system will suffer little damage if you do this. It only takes one command to restart them when you need them.

Other essential key features include

  • Build isolated development environments inside containers.
  • Utilize fewer resources compared using VMs.
  • Share your containers with others to facilitate teamwork.
  • Docker is an open-source program, so there is no cost. Enterprise-level services are also available from the firm behind it, starting at $24 Per month.

Tips and Tricks for Optimizing Wordpress Docker Performance

Deactivate Unnecessary Plugins and Themes

The more plugins and themes you have installed, the slower your WordPress website will be. If a plugin or theme isn’t being used or isn’t optimized for speed, you should turn it off. This can help speed up your site as well as provide security benefits.

Set Up Caching

Caching can help reduce the load time of your WordPress website. Caching is the process of storing static copies of pages so that they don’t have to be made from scratch every time a user visits them. This can dramatically speed up page loading times.

Use a Content Delivery Network (CDN)

A content delivery network (CDN) is a network of servers around the world that serve up static content to users. By using a CDN, you can make sure that your website’s content is delivered as quickly as possible to visitors around the globe.

Compress Images

Images are often the largest files on any web page, so it’s important to make sure they’re compressed. Compressing image sizes helps reduce the complete file size and can make them load faster. There are a number of tools available to help compress images, including WordPress plugins that do the job automatically.

Optimize Your Database

Your WordPress database is where all of your website’s content is stored. Over time, it can become cluttered with unnecessary data, which can slow down your website. You can clean up your database and make it run better by using a WordPress plugin.

Upgrade Your Web Hosting Plan

The web hosting plan you choose makes a big difference in the overall performance of your WordPress website. If your site is growing and getting more traffic, it might be time to upgrade your hosting plan to one that offers better performance.

Use a Lightweight Theme

The WordPress theme you use has an impact on the overall performance of your site. It’s important to choose a theme that is fast, light, and has features like lazy loading and support for AMP pages.

Upgrade Your PHP Version

WordPress websites run on PHP, the programming  language that powers the web. It’s important to make sure you’re running the latest version of PHP for improved performance, security, and compatibility with plugins.


There are several ways to set up basic testing sites and local environments for WordPress development. However, Docker stands out due to its compartmentalization capabilities.

It lets developers quickly set up separate environments with different parts next to each other and turn them on and off whenever they want, which is a big benefit. In addition, it allows for much better resource management than traditional virtual machines.

Using Docker for WordPress development is a great way to save time and money, as well as ensure that your apps are running smoothly. With this guide, you should now be ready to set up containers on your local machine and configure them for development purposes. 

Good luck! 

FAQs on WordPress Docker 

Is Docker free?

Yes, there  are versions of Docker available for free. The Docker Community Edition is the most common type and can be downloaded from the official website.

Can I Ship a WordPress Image to the Production Server?

A WordPress image makes it possible to ship your application quickly and reliably. You can push the Docker image to a production server and have everything set up in no time. 

Can I Run Multi-Containers at Once?

Yes, you can indeed run multiple containers at once on a single machine with Docker. This is much easier than running multiple virtual machines at the same time, as it requires fewer resources.

Can I Scale My WordPress Docker Container?

Yes, you can scale your container up or down to fit your needs. Docker Compose can also be used to set up multiple containers for a single application, which makes it easy to scale.

Does WordPress Need to Be Installed in a Container?

No, but you should install WordPress in a container so that all of its parts are there and can be easily moved from one platform to another. The process needs root privileges, so if you are not logged in as a root user, you will be asked for the sudo password of any non-root user.

What Is the Best Way to Manage Multiple WordPress Sites With Docker?

The best way to manage multiple WordPress sites with Docker is by using a tool called Docker Compose, which allows you to configure all of the services that your container will need in one YAML config file.