Setup an Isolated WordPress Environment Using Docker

Antonio C.

Antonio C.

Docker and WordPress Logos

Programs in containers operate independently of one another while sharing the kernel with other containers in the user space of the host operating system. As a result, running packaged software has less overhead, and containers may now be used with any form of infrastructure. Docker allows container linking, which enables programs running within several containers to communicate with one another.

For WordPress developers, Docker, for instance, is quite helpful. In contrast to WordPress, which often consumes a lot of system resources, Docker enables developers to create a minimal environment without consuming unnecessary server resources or memory.

Docker is an open platform for developing, running, and shipping applications. It helps you separate your infrastructure from your application, lets you ship, deploy, and run applications very quickly. Docker provides an isolated environment called containers, which contains all of the dependencies of a particular project. It is similar to virtual machines but is more lightweight and flexible, getting started quickly.

When you use Docker, you no longer need to rely on the setup of the host machine. The dependencies will be installed for you automatically on an API (Application Programming Interface) communicated via Daemon (a background program ready to perform an operation when needed). Through Daemon, you can start, stop, build, delete, and manage Docker easily.    

It is popular for:

CI (Continuous integration) 

CD (continuous deployment)

This helps when you need anyone to run your application on any operating system and pre-existing setup they have.

Difference between Docker and Virtual Machines

These are similar in some ways, and sometimes they accomplish the same tasks.

Virtual Machines Docker
  • They are the instances of an entire operating system running on the hardware of a single machine. Say you have four virtual machines running on one physical machine that they have.
  • They are isolated environments running that are running an entire operating system.
  • They are managed by Hypervisor (utilizes a lot of memory, CPU and other resources
  • It uses containers that re low level and simply processes running on an isolated environments sharing the host operating system
  • You don’t have multiple VM (Virtual machines) running on different operating systems, you have multiple containers relying on same host operating system
  • But they still are able to run the applications and have their own isolated environment
  • Much smaller in size
  • Takes up less system resources
  • Can be started much quickly


Docker Terminologies

Before showing you how to set up Docker through easy commands, let’s understand some Docker terminologies.


A simple blueprint or template for building Docker containers. You can create your own or use others’. They are based on other images that you can use by modifying them according to your needs for a particular project. Instructions on what is needed to run and set up an application properly.


A place where you store images. The default registry is called Docker hub, which is a website with a number of Docker images. It is like GitHub. In GitHub, you store codes, in Docker, you store images.  


They are the runnable instances of images. They have anything you need to run an application in an isolated environment, like tools, dependencies, software, and more.

Section: Install Docker

Installing a LAMP (Linux, Apache, MySQL, and PHP) or LEMP (Linux, Nginx, MySQL, and PHP) stack in order to run WordPress can be time-consuming. But, you may speed up the process of building up your preferred stack and installing WordPress by using technologies like Docker and Docker Compose. You may utilize images to standardize things like libraries, configuration files, and environment variables rather than manually installing each component one at a time. Run these images thereafter as separate processes using a common operating system. Moreover, Compose allows you to coordinate the communication of different containers, such as an application and database.

First of all, you will have to go to to install Docker. It is available for Windows, Ubuntu, Linux and macOS.

Installing Docker on macOS

Certain prerequisites must be satisfied in order to install Docker on a macOS device:

  • 4GB of Memory with macOS 10.15 or later
  • VirtualBox 4.3.30 version history cannot be installed.

How to install Docker on macOS is detailed below:

  1. Double-click the saved.dmg file to launch Docker for Mac. The Docker icon should then be dropped into your Applications folder.
  2. may be found in your Applications folder. You will be required to provide your password throughout the setup procedure.
  3. Accept the service agreement when offered; failing to do so will result in the installation failing.
  4. When the installation is complete, the Docker menu ought to appear in the status bar of your desktop.

WordPress with Docker

WordPress is also made formally accessible on Docker Hub; use the command below to retrieve the image. Docker will download the most recent version available if the version to download is left blank.

Docker Pull WordPress

WordPress container can take Docker environment variables and parameters:

  1. Set your database password on: WORDPRESS_DB_PASSWORD
  2. Give your container a name on: name WordPress
  3. Item that Links your specific WordPress container with the MariaDB container so that the application interaction: link wordpressdb:mysql
  4. This tells Docker to pass connections from your server’s port HTTP to the containers intrinsic port 80: p 80:80
  5. This sets the WordPress files accessible from outside the container: v “$PWD/html”:/var/www/html
  6. d – Makes the container run on the background of your server
  7. WordPress tells Docker what to install and uses the packages that you installed earlier with the Docker pull WordPress -command.


Now you have to run the below command after replacing the password as you did for the container “MariaDB”

docker run -e WORDPRESS_DB_USER=root -e WORDPRESS_DB_PASSWORD=<password> –name wordpress –link wordpressdb:mysql -p 80:80 -v “$PWD/html”:/var/www/html -d wordpress


Afterwards, to check the installation, access your server’s domain name or IP address in a web browser. The initial WordPress installation page may be reached via http://public IP>/wp-admin/install.php. After completing the setup process, you are done.

Starting WordPress setup page

If you encounter a problem connecting the internal address of the WordPress container to the public IP address of your server, use the following command to eliminate the problematic container:

docker rm wordpress

Make sure no other service is already tied to port 80 before restarting Docker and the database container.

sudo systemctl restart docker

docker start wordpressdb


Then attempt to create the WordPress container once more.

Kudos, you should now have a basic WordPress installation operating inside Docker in a container with a straightforward configuration process. 


Make sure to pay attention to your server’s security before proceeding to develop your new WordPress site. But one thing is for sure that Docker makes configuring your local development environment way easier than ever. Check read our post on how to secure your Linux cloud server to learn more.

Ready To Start Your Project