"It’s about time", I thought early 2020 when decided to refresh this personal website. Started looking into “serverless” alternatives, yet I couldn’t find any compelling stacks to adopt, I’m still attracted to the idea of the zero-cost hosting, and the nostalgic simplicity of HTML-only pages, maybe when all the integrations between the CMS>Generator>Git>Hosting are transparent, I’ll probably take a look again at those, meanwhile, I’ll stick with what I know: WordPress, incorporate Docker in a effort of decoupling components, and finally add a CDN to improve availability and speed in this low-traffic and over-engineered blog. Let’s deploy WordPress using Docker.
TLDR: This post is about deploying WordPress with Docker, increasing speed with a CDN provider and reinforcing security at the same time.
What is Docker?
If you’ve used VirtualBox, VMware or similar, you probably know how Docker works. What Docker (in simple terms) is, it’s a tool that allows to run virtual machines (containers – Docker lingo) within your laptop or your server, the trick is that to make that container as small in size, and not that memory hungry.
For example, say you want to run a database server: MySQL server, instead of running it on a bloated Linux version with components you’d never use -yes those Bluetooth drivers-, you’d use a version on Linux that is very very light such as Alpine, that weights 38MB only, and on that light Linux you install MySQL.
How is this site “dockerized”?
Another Docker lingo: dockerized, meaning how is the structure of containers organized?
Well, I simply leveraged what’s already on the Internet, specifically from this Github repository, where the docker structure is as follows:
Internet > HTTPS Server > NGINX Server > WordPress-FPM Server > MySQL Server
That way, every component is a Docker container with its own external data folder for quick configuration. Looks complex but I work with complexity so nothing new.
So, after the complexities, what are the benefits?
- Decoupling: Every component is somewhat independent of the other, e.g. if I get tired of Nginx I could swap that component with Apache and everything would continue working.
- Always up-to-date: With the inclusion of Watchtower, all Docker images (hard drives) are updated on regular basis.
- I’m free to move VPS: Currently this blog is running on Linode -highly recommended- I’ve been with Linode for years, simple, cost-effective, amazing customer service… but, if things go south, I’m ready just take my data folder, and can deploy my site in minutes somewhere else, even on my local NAS… wait, yes I could 😀
- Personal satisfaction: Yes, I did it.
There’s this website Gtmetrix, will give you all kind of stats and performance recommendations, just enter the name of your website and check how fast it is. To be honest I’ve never got these speeds or responses with previous setups. To get an A (95%) and B (86%) is not small feat, but, to get these, here’s a little trick: CDN.
A CDN (Content Delivery Network) is (again in simple terms) a service that takes your static and/or dynamic content and distribute it (usually free) throughout the world, closer to your users, so your site loads faster.
I didn’t research much on CDN providers, I went directly with Cloudflare, free CDN, that’s what I needed, and I have some friends that use their services as well, so I said, OK let’s give it a try.
One hidden benefit as result of using Cloudflare is that my server’s IP address is now hidden from the exterior world, I tried a nslookup on my domain, and my server never shows up, that is good in a sense that it reduces the chance of direct attacks on my server, the bad, how do I access it? In my case I leveraged another domain I have to do so, added A record on the domain, and good to go.
I encourage you to explore Cloudflare, there are lots of options and security options in both free and paid plans that are worth taking a look. For example: Auto Minify, this avoids to install a plugin in my WordPress, meaning less maintenance for me.
I could rename this post: “WordPress the hard way”, but once you start thinking the Docker way, is hard not to imagine a service without the flexibility that Docker provides: each service within its own container, running autonomously, quick deploy, always update, and with my new best friend: CDN everything under protection, it’s a good start for what’s next on this blog.
I’ll keep writing.