Architecture of a Docker multi-apps server regarding to database Architecture of a Docker multi-apps server regarding to database docker docker

Architecture of a Docker multi-apps server regarding to database


It depends on several factors. Here are some questions to help you to decide.

  • Are the 5-6 apps very similar (i.e., in Docker terms, you could base them on a common image), and are you thinking about deploying more of them, and/or migrating some of them to other servers?

    • YES: then it makes sense to embed the MySQL server in each app, because it will "stick around" with the app, with minimal configuration effort.

    • NO: then there is no compelling reason to embed the MySQL server.

  • Do you want to be able to scale those apps (i.e. load balance requests for a single app on multiple containers), or to scale the MySQL server (to e.g. a master/slave replicated setup) ?

    • YES: then you cannot embed the MySQL server, otherwise, scaling one tier would scale the other tier, which will lead to though headaches.

    • NO: then nothing prevents you from embedding the MySQL server.

  • Do you think that there will be a significant database load on at least one of those apps?

    • YES: then you might want to use separate MySQL servers, because a single app could impede the others.

    • NO: then you can use a single MySQL server.

Embedding the MySQL server is fine if you want a super-easy-to-deploy setup, where you don't need scalability, but you want to be able to spin up new instances super easily, and you want to be able to move instances around without difficulty.

The most flexible setup is the one where you deploy one app container + one MySQL container for each app. If you want to do that, I would suggest to wait for Docker 0.7, which will implement links, which will let you have a basic service discovery mechanism, so that each app container can easily discover the host/port of its database container.

I wouldn't deploy MySQL on the host; if you want a single MySQL install, you can achieve the same result by running a single MySQL container and running it with -p 3306:3306 (it will route the host's 3306/tcp port to the MySQL container's 3306/tcp port).


Since the 5 or 6 apps are small as you described, I will definitely exclude the option of installing a separate MySQL per container for two reasons:

  1. It is waste of server resources, it is almost equivalent to installing MySQL 5 or 6 times on the same server.
  2. It is less flexible (cannot scale DB independently from the apps) and harder to backup.

Having a dedicated MySQL container or installing MySQL on the host directly (i.e. not dockerizied), should have almost the same performance (at the end you will have a native mysql process on the host regardless if it is in the container or not).

The only difference is that you have to mount a volume to persist the data outside the MySQL container, so having a dedicated MySQL container is a better option.