In 2019, I became interested in using Docker when Windows 10 introduced Windows Linux Subsystem 2 and eventually started building my own local development based on Windows 10 WSL2 and Docker aka WP 4 Docker
WP 4 Docker is a local environment that works with Windows, Linux, and macOS with built-in automation. The reason why I started to build something like this because I wanted something that I have full control over and not have to worried about how to do this and that.
So what exactly does WP 4 Docker do for you. Well, it is a local development environment that mainly focuses on WordPress development for themes and plugins at first then it became something more. I was able to add ClassicPress to the list and custom sites where I don’t need WordPress or ClassicPress.
What Does WP 4 Docker Includes
WP 4 Docker uses LEMP (Linux Nginx, MySQL, and PHP). I could have also installed Apache but I figured using Nginx would makes more sense since it was more easier to configure then Apache.
Getting Started with WP 4 Docker
Before you begin, I would like to point out one of the main files that gets used and that file is custom.yml, when you first docker up, the custom.yml will be created from default.yml inside the .global folder and it will generate any sites you want. The only site that will get generated is a sandbox. This is what the config.yml looks like.
sites: sandbox: provision: true repo: https://github.com/benlumia007/wp-4-docker-sites.git host: -sandbox.test
Suppressing prompts with Elevating Privileges
Please make sure you have write access to the hosts file either if you are using Windows, Linux, or macOS. If you are on either Linux or macOS, you can do the following to supress sudo
username ALL=(ALL:ALL) NOPASSWD:ALL
On Windows below
cacls %SYSTEMROOT%\system32\drivers\etc\hosts /E /G username:W
So, let’s get started, let’s go ahead and clone the repository
git clone https://github.com/benlumia007/wp-4-docker.git WordPress cd WordPress npm install sudo npm link
The npm link just allows you to install a special command called wp4docker.
provision Create new WordPress site or sites restart Restarts one or more containers shell Opens a shell for a specific container ( default: nginx ) start Starts one or more containers stop Stops one or more containers up Starts one or more containers down Destroys one or more containers pull Pull image or images
Let’s do a wp4docker up, this will pull images first then continues on. After it finished, then wp4docker provision to provision to create a dashboard, a WordPress site (sandbox), PHPMyAdmin, and tls-ca for self-signed certificates. After that is done, let’s do a wp4docker restart Nginx.
Please note that you will need to install the certificate ca.crt so that you can use all sites which will all be redirected to https.