Mariadb best practices / setup / passwords / multiple databases

I’ve only been using docker for a short while, and while I love it, I have a couple of questions about mariadb setup using compose; I apologize in advance if they’re too noobish or if they are in the wrong forum section.

I know that we can optionally specify a database name, database user, and database password, in addition to the root password, but the nextcloud image isn’t doing this for its mariadb, so I was wondering which is considered the “best practice”?

Furthermore, say I was hosting another service that used mariadb, like the bitwardenrs/server-mysql. Would best practice be to create a second database under the mariadb container, or create a second mariadb container the same way you would for nextcloud?

Finally, reading the documentation it seems that instead of having my passwords for the initial setup in the docker compose file, I can put them in /config/env, which is helpful. I guess I was wondering what the best practice would be for docker passwords if you aren’t using docker Swarm.

1 Like

Some apps like nextcloud like to create their own databases so you put in your root account or any admin account details and they take care of the rest.

Other apps want you to first create the users and the databases and then tell the app what they are. I’m those cases, you can use the environment variables in mariadb image to auto create those.

With regards to multiple mariadb instances, if you’re not short on ram, you can run a separate mariadb instance for each container that needs it. That way, you can do proper backups and if something goes wrong, you can nuke and recreate from a backup a single mariadb instance.

If you’re proficient enough in managing mysql databases (or short on ram), put all data in the same mariadb container but if something goes wrong with a container, you may have to manually clean up the databases.

You could use the same container for multiple database driven containers. To manage mariadb you could install phpmyadmin
This makes it very easy to setup, create and manage databases.

And for backup you could use mysqldump.

I have setup all my containers in docker this way and scheduled mysqldump backups.

That’s a neat idea too. I mean, I have to use SQL at work as I’m a developer, but that’s usually in Oracle (or now postgres, as they’re considering using that for their data warehouse and I’m doing a POC for that with an ETL tool), but I’m by no means a DBA so that tip about the backups helps.

I knew having two databases in the same mariadb container was possible, I guess I’m asking which is the “best practice” way. I’m new to Docker and containers in general so I am trying to do things right. I am confident I can maintain it going forward in either case.

IMHO I think “the best practice” would be to install one mariadb container to manage the divers databases and make sure to setup a good backup plan for each database. This way I guess you couldn’t screw up things when something goes wrong with the container. Maintaining one Mariadb container is also more work and structure wise efficient. You only have one container to update on regularly basis.