WordPress in Docker: Grey-Cloud DNS and a Missing wp-cli

Moving WordPress off a hosted plan onto Docker with Caddy: why proxied Cloudflare DNS broke Let's Encrypt validation, and why wp-cli lives in a second image.

I moved this blog off WordPress.com and onto my own VPS, and the migration itself was the easy part — the two days after it were not. The stack is small and boring on purpose: the official wordpress:php8.3-apache image, mariadb:11.4 behind it, and caddy:2 in front handling TLS. Caddy issues and renews the Let’s Encrypt certificate on its own, which is the whole reason I picked it over hand-rolling nginx plus certbot. What I did not expect was that a DNS toggle in Cloudflare would stop certificate issuance dead, and that the WordPress image I chose has no wp-cli inside it at all. Both cost me real time, and both are the kind of thing that only shows up when you actually run the stack instead of reading about it. I keep the longer version of these notes in my self-hosting security notes, but this is the migration story as it happened.

Why I left the hosted platform at all

The hosted version was fine for writing. It stopped being fine the moment I wanted to do anything adjacent to the blog — put it behind my own monitoring, run a staging copy, keep the database somewhere I can actually query, ship the access logs into the same place as everything else on the box. On a hosted plan you get a dashboard, not a filesystem. Every one of those small wants turned into “not supported” or “upgrade your plan.”

So the requirement list was short. I wanted the site to be a set of containers I could tear down and rebuild from a config, TLS that renews without me touching it, and a database I can open a client against whenever I feel like it. I did not want a control panel, I did not want a plugin that promises to do the reverse proxy for me, and I did not want to be the person manually renewing certificates at 2am because a cron job quietly died.

The three-container shape

The whole thing is three images, each doing one job.

wordpress:php8.3-apache   # PHP + Apache, serves the app
mariadb:11.4              # the database
caddy:2                   # reverse proxy + automatic Let's Encrypt TLS

Apache inside the WordPress container is the thing people second-guess. It is not the fastest option and it is not the most fashionable, but it is the officially maintained image with the PHP version I wanted, and it means the container speaks HTTP on a normal port with no extra configuration layer between Caddy and PHP. Caddy terminates TLS, forwards plain HTTP into the WordPress container, and that is the entire request path. One hop, one certificate, no chain of three proxies where a header gets lost and you spend an evening reading logs.

The database being a separate container matters more than it sounds. MariaDB keeps its data in its own volume, WordPress keeps its uploads in its own volume, and Caddy keeps its certificates in its own. That separation is what makes the rebuild story credible: if I break the application layer, I throw away one container and one volume and point the new one at the same database. If I break the database, the uploads are untouched. Nothing about the site lives in a place I cannot name.

Caddy and the certificate I assumed would just work

Caddy’s automatic HTTPS is the part that sells itself. You give it a hostname, it goes and gets a certificate, it renews before expiry, and you never think about it again. That is genuinely how it behaved once the DNS was right. The problem was that it did not tell me the DNS was wrong — it just kept failing to get a certificate, and the site sat there serving nothing useful while I assumed the problem was in the container.

That is the trap with automation: when it works you never learn its failure modes, and when it fails the error is buried under a layer you did not write. Caddy was doing exactly what it was told. The thing standing between it and a certificate was a DNS setting two services away.

Gotcha one: the orange cloud breaks HTTP-01

My DNS lives at Cloudflare, and like most people I had the record proxied — the orange cloud, the one that puts Cloudflare’s edge in front of the origin and hides the real IP. It is the default people reach for, it looks like free protection, and it is the reason Let’s Encrypt could not validate my domain.

Here is the mechanism, and it is worth understanding rather than just toggling. Caddy gets certificates through the HTTP-01 challenge: Let’s Encrypt asks for a specific file at a specific path on the domain, and if it gets the right answer, it issues the certificate. That validation request has to reach my Caddy container and be answered by it. With the record proxied, the request lands on Cloudflare’s edge first. Cloudflare terminates it, and what my origin sees — or does not see — is not the challenge the ACME server is checking for. The validation fails, the issuance fails, and the only visible symptom on my side is a certificate that never appears.

What made this genuinely painful was the diagnosis, because every layer looked innocent in isolation. The containers were up. The WordPress container answered on its internal address. Caddy’s config was valid and it was logging normal startup messages. The database was fine. Nothing in the application stack was broken, and I kept restarting things that did not need restarting because the failure was upstream of everything I was looking at.

What eventually pointed at DNS was noticing that the failure was specifically at the certificate step and not at the routing step. Once I framed it as “the challenge is not arriving,” the proxied record became the obvious suspect. The fix was to set that one DNS record to “grey cloud” — DNS-only, not proxied — so the validation request resolves straight to my VPS and reaches Caddy directly. Issuance succeeded immediately. Caddy got the certificate, started serving HTTPS, and has renewed on its own since.

The trade-off is real and I want to be honest about it. Grey cloud means the origin IP is visible in DNS, and Cloudflare’s edge features do not apply to that hostname. For a blog on a VPS that is an acceptable trade — I get a working certificate and a direct path I can reason about, and I handle the rest at the firewall and at the application layer instead of pretending the proxy is my security boundary. If I ever want the proxy back in front, I would have to move to a DNS-01 challenge or terminate TLS at the edge and re-originate, and neither of those is worth it for this site today.

Gotcha two: the WordPress image has no wp-cli

The second surprise was smaller in blast radius and bigger in annoyance: wordpress:php8.3-apache ships PHP and Apache and the WordPress files, and that is essentially it. There is no wp-cli binary inside that container. I did not think about this until I needed to do something that is trivial with wp-cli and miserable without it — inspecting options, touching users, running a search-replace after the domain changed.

The instinct is to install wp-cli into the running container. I did not want to do that, for the same reason I did not want a pile of plugins: anything I install by hand into a container is gone the next time the container is recreated, and it makes the image drift from what I can rebuild. A container I have to hand-modify is a container I cannot honestly call reproducible.

The clean answer is a second image that exists only to run wp-cli: wordpress:cli. It is the same project, published as a CLI image, and it expects the same WordPress files and the same database connection. I run wp-cli work through that image instead of through the web container, and the web container stays exactly as shipped. That distinction is the whole trick — the application image serves requests, the CLI image performs administration, and neither has to be modified to do the other’s job.

The same principle applies to SQL. I do not want to reach into the MariaDB container and improvise; I use the mariadb client to talk to the database properly, with the same credentials the application uses. Any direct SQL work — checking what a migration actually did to a table, confirming a row before and after a change — happens through that client rather than through a plugin that promises to run queries for me. When something goes wrong at the database level, I want to be the one holding the connection, with the query in front of me.

What this changed in practice is that the “how do I do X” question now has two answers instead of one, and I have to pick the right one. If X is serving a page, it belongs to the web container. If X is anything an administrator would do from a shell — options, users, content, search-replace — it belongs to the CLI image. If X is data, it belongs to the mariadb client. Once I internalised that split, the stack got much easier to operate, because I stopped trying to make one container do everything.

What the rebuild actually looks like

The payoff for all of this is that the site is now three declarative pieces plus three volumes, and I can describe the whole thing without opening a browser. WordPress code and uploads live in their volume; MariaDB data lives in its volume; Caddy’s certificates and state live in theirs. The configuration is text. If the VPS disappeared tomorrow, the recovery path is: bring up the database, restore the database volume, bring up WordPress against it, bring up Caddy with the same hostname, and confirm the certificate issues. The only step in that list that ever bit me is the last one, and only because of the DNS record — which is exactly why I now check the DNS before I check anything else.

That is also why I keep the grey-cloud decision written down. It is not obvious from looking at the Cloudflare dashboard months later why that one record is unproxied while others are not. A future me — or anyone else who inherits this box — will see an inconsistency and be tempted to “fix” it by turning the proxy back on, and that will break certificate renewal silently until the certificate expires. The note is the difference between a configuration and a landmine.

What I would do differently

  1. Set the DNS record to DNS-only before the first container start, not after the first failed certificate. The failure looks like an application problem, and I spent time debugging the wrong layer.
  2. Decide up front which image owns which job: web serves, CLI administers, the mariadb client queries. Mixing them is how containers start drifting from their images.
  3. Treat automated TLS as something to verify explicitly after go-live — confirm the certificate is actually issued for the hostname and that renewal has a path, rather than assuming “Caddy handles it” is the same as “it happened.”
  4. Write down every non-default decision, especially the proxied-versus-unproxied one. The stack is only reproducible if the reasoning survives alongside the config.
  5. Keep administrative tooling out of the serving image. A hand-modified container is a container you cannot rebuild, and that defeats the point of running containers at all.

The short version

Self-hosting WordPress in Docker with Caddy is genuinely a small stack — three images, three volumes, one hostname. The difficulty is never the happy path; it is the two assumptions you make without noticing. I assumed Cloudflare’s proxy was compatible with HTTP-01 validation, and it was not, so certificate issuance failed while every container looked healthy. I assumed the WordPress image would have wp-cli, and it did not, so administrative work had to move to the dedicated CLI image and database work to the mariadb client. Neither mistake was exotic. Both were invisible until the stack was actually running and something needed to happen.

The result is a blog I can rebuild from text, with TLS I do not babysit, and a clear line between the container that serves and the tooling that administers. That is worth the two days it cost — and next time, I will check the DNS record first.

Related

Filed under: Home Lab, Automation, Docker, Home Lab, Self-Hosting, VPS