Ready to take the dive and modernize WordPress with Docker?
Long story short, it can be definitely be worth it depending on your use case. From our experience, you can save yourself hours, or really over-engineer and dig yourself a hole.
We're very grateful for WordPress, and it even runs our blog for Server Side Up. The only downside with WordPress is it has a lot of history with it. That means the core was written with in a mindset before all of the fancy and flashy methods that we have today.
The most important thing you need to remember is always try to do things "The WordPress Way".
The more you work with it, the less you are fighting the platform.
Introducing modern toolsets to WordPress may allow you to get WordPress up and running, but severely limit you to the rest of the community tools.
This could be things like (but not limited to):
- Using NGINX as the web server
- Deploying updates by packaging WordPress into a Docker Image
- Using too new of a PHP version
- Using Roots Bedrock to modernize your development flow
We've tried all of these above and we learned that most of the plugins that we relied on had issues with this.
We embrace these principals:
- Always do things "The WordPress Way"
- Keep plugin installation to a minimum
- Always use Apache as the web server (too many plugins expect Apache)
- Only commit your own source code (not WordPress core or another plugin)
We run WordPress in production on Docker Swarm using:
- Traefik (handles SSL automatically with Let's Encrypt)
- Our PHP-Apache image (this is optimized for WordPress)
- MariaDB (the "non-Oracle" alternative to MySQL)
We attempted to deploy WordPress with rolling updates (like we do with Laravel) by packaging WordPress into a Docker image use theRoots Bedrock framework, but we ran into a ton of issues with community plugins.
Our most stable solution (following "The WordPress Way") is to:
- Mount
/var/www/html
of the container to the host - At the host container, run an SSH
git pull
from our CI system
Ugly, but it works π€·ββοΈ
In this repository, you will find a basic boilerplate of what we use when we start a new WordPress project.
git@github.com:serversideup/docker-wordpress.git
# Make sure you are in the project folder
cd docker-wordpress
# Download and extract WordPress
wget -c https://wordpress.org/latest.tar.gz -O - | tar -xz -C public/ --strip=1 wordpress/
This example uses "wordpress.dev.test" for the URL, so we would add this to our hosts file:
127.0.0.1 wordpress.dev.test
We use Docker Overrides to separate our environments.
For now use this ugly command, but we are working on open sourcing a tool called Spin that will greatly shorten this:
docker compose -f docker-compose.yml -f docker-compose.dev.yml up
docker-wordpress-mariadb-1 | [Note] [Entrypoint]: Creating database wordpress
docker-wordpress-mariadb-1 | [Note] [Entrypoint]: Creating user wordpress_database_user
Just go to https://wordpress.dev.test/ in your browser. You should see the WordPress install wizard.
The credentials are set in docker-compose.dev.yml
. By default they are:
- Database Name: wordpress
- Database Username: wordpress_database_user
- Database Password: wordpress_database_password
- Database Host: mariadb (the name of the mariadb service in the docker-compose.yml file)
We use Docker Swarm for running WordPress in production (just because it is so much simpler than Kubernetes).I left our docker-compose.prod.yml
file in there, but there are a number of things that we do in production that would take longer than writing this document π
If there is interest on how we do this, just let us know. Hit me up on Twitter and express your interest on learning more.
For this first commit, I just wanted to at least give you a perspective on how we run things.
As always, if you know of a better way, let us know!!
We're Dan and Jay - a two person team with a passion for open source products. We created Server Side Up to help share what we learn.
- π Blog - Get the latest guides and free courses on all things web/mobile development.
- π Community - Get friendly help from our community members.
- π€΅ββοΈ Get Professional Help - Get video + screen-sharing support from the core contributors.
- π» GitHub - Check out our other open source projects.
- π« Newsletter - Skip the algorithms and get quality content right to your inbox.
- π₯ Twitter - You can also follow Dan and Jay.
- β€οΈ Sponsor Us - Please consider sponsoring us so we can create more helpful resources.
If you appreciate this project, be sure to check out our other projects.
- The Ultimate Guide to Building APIs & SPAs: Build web & mobile apps from the same codebase.
- Building Multi-Platform Browser Extensions: Ship extensions to all browsers from the same codebase.
- Bugflow: Get visual bug reports directly in GitHub, GitLab, and more.
- SelfHost Pro: Connect Stripe or Lemonsqueezy to a private docker registry for self-hosted apps.
- AmplitudeJS: Open-source HTML5 & JavaScript Web Audio Library.
- Spin: Laravel Sail alternative for running Docker from development β production.
- Financial Freedom: Open source alternative to Mint, YNAB, & Monarch Money.