I have a server with nginx/fpm/mySQL and multiple WP installations, and I want to dockerize the whole installation; when it comes to WP, it’s pretty much crystal clear, each website will be hosted on its own LAMP image, having traefik to handle all the traffic.
I’m a bit confused about the MySQL service though; what’s the best approach? To have a single MySQL image which will load multiple databases (each WP will have its own database) or setup separate images (therefore MySQL services), separately for each WP installation?
Thank you!
2
Answers
It’s depend on your business model, whether you would like to offer every single site a separated root access to their database or not. To my experience, WordPress also support multiple site feature in which, every site will have their separated content and template and plugins and so on, which is well designed to work in single database and single docker image (your LAMP).
If you can use a single MySQL docker container, it will offer much more better performance than multiple MySQL containers which helps to reduce overhead costs for running multiple containers and it will be much more easier in management.
I believe that if your expectation is just to have multiple WordPress site without providing any server access to your user, please take a look at the WordPress Multisite and use just single container for every kind of service.
Option 1: Single MySQL Image
with each WordPress installation having its own database, this approach can simplify your setup, as you only need to manage one MySQL image, and it can make backups and migrations easier to manage. However, if one WordPress installation causes issues with the MySQL instance, it could potentially impact other WordPress installations.
Option 2: Multiple MySQL Images
using separate MySQL images for each WordPress installation, This approach allows you to isolate each WordPress installation’s database, so issues with one WordPress installation’s database will not affect other installations. However, this approach can add complexity to your setup, as you will need to manage multiple MySQL instances.
you see the tradeoffs in your situationthe best approach depends on your specific use case and requirements.
If you expect each WordPress installation to have a significant amount of traffic or if you have strict data isolation requirements, using separate MySQL images may be the better option. If you have a smaller number of WordPress installations or if you value simplicity over strict isolation, using a single MySQL image may be the better choice.
Either way, you will need to configure your Docker Compose setup to manage the MySQL images and link them to the appropriate WordPress installations. Additionally, you may want to consider using Docker volumes to persist your MySQL data and configurations between container restarts.