Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple docker containers for mysql or one instance with multiple databases

I have a question regarding best practices using docker containers.

I need one database for each application I develop. Now my question is whether I should use one mysql docker instance with multiple databases inside or should I create one instance for each database. The disadvantage I see with creating one instance per database is that I can't have a user which has access to all database. I know this is a pro for security reasons but when I try to backup from a client than I need to go in every instance for backup up. And isn't multiple instance using to much overhead of resources (although mysql may be using less resource, but using e.x. mssql instance which is quit bigger may cause resource problems later)

My question is what is the common way to do it with docker and what are the pros and contras?

like image 860
hesyar Avatar asked Jan 26 '17 21:01

hesyar


People also ask

Can I have multiple Docker containers?

With Docker compose, you can configure and start multiple containers with a single yaml file. This is really helpful if you are working on a technology stack with multiple technologies.

Can multiple Docker containers use the same port?

Surprisingly or not, neither Docker nor Podman support exposing multiple containers on the same host's port right out of the box. Example: docker-compose failing scenario with "Service specifies a port on the host. If multiple containers for this service are created on a single host, the port will clash."

Can a VM run multiple Docker containers?

You can not deploy multiple containers per VM. Please consider this limitation when deploying containers on VMs: 1. You can only deploy one container for each VM instance.


1 Answers

Docker is especially suited to the deployment of microservices. The following links discuss two strategies with regard to the use of databases:

  1. Database per service
  2. Shared database

I personally favour the use of a single database per service and extend that to the deployment of separate instances of a database server. This ensures services are loosely coupled, should one service suffer a DB outage, it won't impact another.

like image 73
Mark O'Connor Avatar answered Sep 23 '22 19:09

Mark O'Connor