Docker and it’s Internal Networking
Had an interesting little issue happen today. I have a VPS where I host this and several other wordpress instances for friends. All of it runs inside nice orderly docker containers dictated by a compose file. All of them share the same network to talk to the reverse proxy.
The wordpress container talks to the database container through docker’s use of internal DNS referencing the name of the service. Considering I use the same template for each instance there’s now a whole bunch of wpdb containers and no clear way to tell which one is which.
Its laid out more clearly here by someone who was experiencing the same intermittent database errors.
https://stackoverflow.com/questions/78983153/intermittent-error-establishing-a-database-connection-errors-with-wordpress-on
Turns out there’s a several years old discussion about this on docker-compose github: https://github.com/docker/compose/issues/8223
Best workaround for now is to have clearly labeled aliases for your database containers, and tell your app to connect to that hostname!
Kind of a lazily written article on my part tbh but its late and I just finished debugging this infernal issue.