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!

Similar Posts

One Comment

Leave a Reply to stefenauris Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.