Is it recommended to use containers for databases?

Viewed 82

I have searched for information about it but still cannot find anything convincing.

I have multiple containerized websites with apache and php, these in turn are exposed through a reverse proxy with virtual hosts for each container, but, I've been thinking about the database, most use mariadb 5.5 but there is one site web required by mariadb 10.

I was wondering if it was a good idea for each container on each website to embed its own instance of mariadb or create a unique container for this, but I have some doubts.

Mariadb uses its own load balancing system, the container will affect its use if it had to raise multiple instances of the same database even though they all use the same data directory? I'm wondering if the engine will have to do the same indexing multiple times or there will be conflict in the use of files.

Having the website in a container has no problems because the files do not undergo changes and the logs and uploaded files are stored in persistent volumes, but in the case of the database it is different because I do not know if it is a good idea that multiple engines make use of the same data directory.

In a productive environment where the database has a high query load, is it recommended to use a container? Or is it better to embed the database inside the website container or do a native installation on the server?

In which cases should I choose one or the other option?

2 Answers

Absolutely do not have 2 databases share the same data directory. Only 1 database server should manage its own volume.

If you need more databases because you want high availability or are worried about load, each needs to manage its own data directory and sync with each other via replication.

I'd say that using containers for database engines is a bit uncommon outside of development setups, but not unheard of especially if you want to be able to scale fast. I don't think it's super easy to automate all of this.

Databases are critical services. In my opinion, you shouldn't use use Docker for production databases. But You wouldn’t think twice about using Docker in a local development environment

Related