So I’m in the process of (re-) setting up my homelab and unsure about how to handle databases. Many images require a database, which the docker-compose usually provides inside the stack.

Now my question, shall I have 1 database container which is accessed by all containers? Or shall I have a separate container for each service?

For critical services, which shall have as few dependencies as possible I’m already using sqlite or a similar solution.

Also on a sidenote: I have two docker hosts, can I let the containers of 1 hypervisors use the same internal docker network?

TIA!

  • anteaters@feddit.de
    link
    fedilink
    English
    arrow-up
    16
    ·
    1 year ago

    I wondered about that myself these days and decided to give each stack its own db. Makes it easier to throw a stack into the bin without having to manually prune the associated databases. I might end up running a database container anyways for tests and side projects and things like that but service stacks get their own db of their choice.

  • MaggiWuerze@feddit.de
    link
    fedilink
    arrow-up
    13
    ·
    1 year ago

    The cost of running a db container for each stack is negligible compared to the comfort of not having to clean up your main database container after you just tried some random container. Then you also have different requirements by different containers, each asking for a specific database for whatever reason and lastly you have another level of seperation between your services

  • Smk@lemmy.ca
    link
    fedilink
    arrow-up
    8
    ·
    1 year ago

    1 db per stack. Not worth your time to secure, configure and debug one big db.

  • Durotar@lemmy.ml
    link
    fedilink
    arrow-up
    6
    ·
    edit-2
    1 year ago

    One database for many different services could pose a security risk, though it should be extremely low if each service can access only its own database. However, it’d be harder to distribute services across different hosts if you ever decided to do that. Also, different services could require or work better with different database types. I prefer to use separate database containers.

  • Outcide@lemmy.world
    link
    fedilink
    arrow-up
    4
    ·
    1 year ago

    Unless you are very constrained on resources, using a database per application is much easier.

  • palitu@lemmy.perthchat.org
    link
    fedilink
    arrow-up
    2
    ·
    1 year ago

    I agree with the posts above. Db per stack/service.

    They are cheap, disposable, ring fenced from causing issues with other dB’s, exact version that has been tested on.

    The list is endless. We’ll, I’m at my end.

    Oo. Typically compose has everything you need prewritten including the db.

  • lemming007@lemm.ee
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

    Not only do I prefer separate db for each stack, ideally the db and app are in the same container. Fewer containers to manage and makes the app nice and self-contained.

  • Ruud@lemmy.worldM
    link
    fedilink
    arrow-up
    2
    arrow-down
    1
    ·
    1 year ago

    Backup / restore gets complicated if you have multiple apps in 1 dB

    • jsnfwlr@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      1 year ago

      No one said a single DB. You can have multiple DBs in a single container, and then use something like databacker/mysql-backup container which solves the complexity of multiple db backups for mariaDB and MySQL

      • Ruud@lemmy.worldM
        link
        fedilink
        arrow-up
        2
        ·
        1 year ago

        Yes, terminology… I mean single instance. And although you can create pg_dumps of separate databases, a true (online) backup of separate databases is difficult. Tools like pgbackrest or barman don’t support it. (I mainly focus on Postgres)