I would like to run multiple PHP applications (different php versions, some of them legacy). So every application would be in executed as separate container(s) - nginx + php. Theoretically, the containers could “share” one common container with maria db or I could run multiple maria db containers. I think the second approach is better for the separation / portability reasons, but I’m wondering if multiple db containers won’t cause too much overhead (cpu, memory).
Depends on what your goal is. Development or production. In production, if you have unlimited resources, sure, you can run new Mariadb database servers for each projects. Or if the projects require very special, different database optimization. Otherwise one database server is enough in which you create multiple databases. In development, I would use separate database servers for each project, since I could delete and recreate everything more easily while developing, but I would only have one running.
When I started working with containers, I also saw that people added a database server service to each compsoe project, but those were mostly for development. Then my database server used at least half of the resources of my VPS.
You can always decide that your project is so big that it requires its own database server, but it shouldn’t be the default approach. MariaDB was not designed for that (unless they optimized for it since I worked with databases).