Docker is a virtualization platform that enables the development and distribution of bundled applications inside “containers.” These containers are hosted by a software called “Docker Engine.” It’s responsible for managing and running the applications found in the containers.
In this video we’ll take a look at installing WordPress on Docker! WordPress is open source software you can use to create a beautiful website, blog, or app. In order to setup a WordPress container on your Docker server, you’ll need a few additional things. Apr 13, 2021 MariaDB in a container. Before installing WordPress with Docker you will need to have somewhere to store the data. MariaDB is a community-developed relational database management system and a drop-in replacement for MySQL. However, by using tools like Docker and Docker Compose, you can simplify the process of setting up your preferred stack and installing WordPress. Instead of installing individual components by hand, you can use images, which standardize things like libraries, configuration files, and environment variables, and run these images in containers. This article covers how to setup wordpress with docker using docker-compose quickly with Apache, PHP and MySQL. WordPress is a free and open source blogging tool and a content management system (CMS) based on PHP and MySQL, which runs on a web hosting service. Features include a plugin architecture and a template system. WordPress is used by more than 22.0% of the top 10 million websites as of August 2013. WordPress is the most popular blogging system in.
Thus, with Docker, it is possible to deploy a preconfigured AMP (Apache, MySQL, and PHP) stack to host a WordPress site. You don’t need to know the basics of web hosting and install Apache, MySQL, and PHP manually on your workstation.
Docker is not just for deploying AMP stacks – the Docker Hub offers hundreds of free, ready-to-use containers for multiple applications.
In this tutorial, we’ll see how to use Docker to install WordPress locally on your Windows desktop.
Step #1: Installing the Docker Desktop
The first step is to install the Docker Desktop application on your workstation. Docker is available in two editions: Docker CE, for Community Edition, and Docker EE, for Enterprise Edition. Therefore, we will use the Docker CE.
Important: Docker can not co-habit with VirtualBox. Therefore, if you use VirtualBox, it will no longer be functional after installing Docker.
To download Docker Desktop for Windows 10, go to:
Note that you will need to register to download the software.
Run the Docker Desktop installer leaving all the default options. When the installation is complete, you will be prompted to log out of your Windows session and log back on.
After opening a new Windows session, start the “Docker Desktop” application. You will then be prompted to enable “Hyper-V” and “Containers” so that Docker can work properly. Click on “Ok” to proceed.
Once the activation of “Hyper-V” and “Containers” is complete, your computer will restart automatically.
Step #2: Modifying the “hosts” File
For this tutorial, I’ll install WordPress for the “webmestre101.home.lan” domain. We’ll add an entry to the Windows “hosts” file so that we can use this domain name to access the WordPress site.
Right-click on the Notepad application icon and select Run as administrator:
Now open c:windowssystem32driversetchosts in Notepad. Insert a new line at the very end of the file. This line must contain your domain name and needs to point to the IP address 127.0.0.1.
Save the file and close Notepad.
Step #3: Creating the Docker Compose File
To install WordPress locally, we’ll need two Docker containers:
- WordPress: The WordPress container contains Apache and PHP, which simplifies the task.
- MySQL: This is the official Docker container of the MySQL database server.
When multiple Docker containers are running simultaneously, it’s best to use Docker Compose. On Windows, Docker Compose is included in the installation of Docker Desktop, so no need to install it manually.
Docker Compose is used to provide container configuration parameters and to establish dependencies between them. So, in our case, the WordPress container depends on the MySQL container. The WordPress container must wait for the MySQL service to be active before starting.
Create the following folders on your “C:” drive:
Then create a file named docker-compose.yml into c:dockerwordpress and copy the following content:
For the database to be created automatically when the MySQL container starts, create a file named init.sql also into “c:dockerwordpress.” Insert the SQL statements below:
Thus, the “wordpress” database will be created when the MySQL container is started if it does not already exist. The same is true for the user account of the same name.
Step #4: Starting the Docker Containers
Open a command prompt window by pressing the Windows+R keys and type
Type this command to change the directory:
Then start the containers in the background using docker-compose with the “-d” switch:
During the first startup, Docker downloads the images for WordPress and MySQL, which may take a while:
When the downloads are complete, the containers will start:
When you start the containers, Docker Desktop may ask you if you want to share the “C:” drive on your computer. You must click “Yes” so that MySQL can create the database files.
Install Wordpress Docker For Mac
If you have error messages while starting the containers, type this command to stop them first:
Start the containers again but this time omitting the “-d” switch:
The “-d” parameter is used to run the containers in the background. By eliminating this parameter, the run logs are displayed on the screen:
In some cases, this can help you diagnose problems. To stop the Docker containers, press CTRL+C:
Step #5: Configuring WordPress
At this point, all you have to do is set up WordPress as you usually do. Use your web browser to access the site:
Note that there is no SSL certificate installed so you must access the site at “http://yourdomain.com.”
This type of installation is ideal for working offline or for showing a website mockup to a customer, for example. All files are contained in one directory (c:dockerwordpress), so it’s easy to copy or move the site to another computer.
As for WordPress, all the files are in
c:dockerwordpresswordpress_files. It is, therefore, possible for you to edit a theme locally and then copy it to the production server when the development is complete.
However, if you need to install and manage multiple WordPress sites locally, it would be easier to use tools such as CapRover and EasyEngine. These tools automate the deployment of WordPress sites (and even other types of sites).
One of the most popular articles on my website is “Configure a local WordPress development on macOS from scratch”. I have recently used Docker a lot so I decided to tackle the same subject again but this time using containers.
This is not a Docker tutorial although by following along you learn how helpful this tool can be. I highly encourage you to familiarize yourself with few basic concepts like: images, containers, networks and volumes. Having a Docker app installed makes a lot of sense too. Regular readers know that I am a great friend with Homebrew. Yes, you can use it to download Docker too.
Wordpress + MySQL + phpMyAdmin #
To comfortably work with WordPress in a bare-bones local environment two components are required, although a third one is nice to have in some circumstances.
- MySQL or MariaDB database
- Database GUI like phpMyAdmin (optional)
Docker compose is a tool for creating multi-container Docker applications defined using single
docker-compose.yml file (
.yaml extension works just fine). Sounds like a fantastic method to connect our three building blocks together. I will do my best to provide helpful descriptions and comments to each of the core building blocks. Start by making a new directory for your website, create a
docker-compose.yml in there and let’s finally get into the meat of this article.
That’s it — time to build our stack! Bear in mind that when you run it for a first time it is going to download all necessary stack images. Every subsequent invocation is going to be almost instant.
Hopefully you found this helpful. This simple setup helps me a lot to spin up a new WordPress from scratch in absolutely no time.
Ps. For simple websites like this one don’t use Wordpress. Use Hugo instead :)
Hey - Thanks for the nice write, its been helpful. I was windows for a long time and using wamp for my wordpress sites and thinking to switch over to docker now. Wanted to know your experience with the docker in comparison to standalone php-apache-mysql setup. Which one do you use? and does each of your wordpress site have a separate docker-compose file? or there is only one docker-compose file you use and have all your sites inside it.
Docker all the things :)
For each project I create new Docker compose file.
Hopefully that helps.
Have great day 🥑
On the screen where we have to put database details, what hostname should I put for mysql?
That should come preconfigured when you set it up like I did. The piece of config that decides about it is this:
Thanks for reply, I am asking about this screen. What information should I put here... https://uploads.disquscdn.c...
What do I do if the ports are already in use? I attempted to kill the ports used but was not able to, so I tried changing them in the config file but still couldn't get this to run.
Hi Pawel! Thanks for nice starting point to create WordPress in seconds but I have question.. I'm using PhpStorm and when it only showing all from `wp-content` directory PhpStorm does not hint the core functions because there are not in project. Do you know how to configure it to use the function hints?
I see what is going on. I am affraid that in this case you have to expose a project root level in your volume
['./:/var/www/html']to make PhpStorm correctly infer WP core methods. I am not a PhpStorm user and potentially there is a much better way. Sorry for being not too helpful.
Have a great day 🥑
Hi Pawel! Nice tutorial, thanks! Question though - how would you mount php.ini ? I'm using Ubuntu on WSL.
Great tutorial. However, I also need .htaccess file on my wp folder because some plugins and also WP itself is changing it. How to do that?
Hi Pawel, thanks a lot for this tutorial. I followed your steps, but I cant edit the files of the volume. They all have user `www-data` while my user is adam. File permission is 644, so I can't even edit them, if I add `www-data` group to `adam`. Any advice how to fix it? Also asked this here: https://stackoverflow.com/q...
I recommend to try Codelobster IDE for Wordpress development - http://www.codelobster.com/wordpress.html