Hello,

As the title suggests, how do you manage your DBs for docker services.

Do you spin a new DB for every new docker cluster or do you have a centralized DB that is accessible to the docker clusters.

What are the pros and cons of both method?

For the moment, I spin a new DB for every services as I feel it is easier to backup the service in case of a problem.

  • JC1@lemmy.ca
    link
    fedilink
    English
    arrow-up
    0
    ·
    14 days ago

    I work per stack. Each stack can have multiple services/containers. So one db per stack. I usually work with the compose file provided by the app I want to run and they usually provide their database container in those. My persistent data for a stack is in a single folder for every services. For backup, I only have to backup the compose and environment files and also the persistent folder and that’s it. Every stack is independent from each other so it’s easier to move them from a server to another if I want to use more than one server.

    I used to use only one db container for all db. It worked well, until I had a data corruption issue. I had to rollback from a backup for all services that used this db. Then I moved to 1 db per stack and it happened again, but this time, only that stack was impacted, so no big deal. Just did a rollback and everything was fine.

  • PeriodicallyPedantic@lemmy.ca
    link
    fedilink
    English
    arrow-up
    0
    ·
    13 days ago

    I just let each docker stack get its own.
    Often different services need different versions or update between versions at different cadences, so I don’t want to deal managing all that.

  • bacon_pdp@lemmy.world
    link
    fedilink
    English
    arrow-up
    0
    ·
    14 days ago

    One database service but separate databases running inside of the service. Each database has 3 accounts: table_owner (no remote access), proc_owner (only table specific permissions and the owner of all stored procedures; no remote access) and application_account (no table access and only execute permissions on the proc_owner’s stored procedures).

    Which means that even if the application is compromised, it can not compromise the database. It can only use approved stored procedures that check their inputs and abort on the smallest deviation from expected inputs.

  • irmadlad@lemmy.world
    link
    fedilink
    English
    arrow-up
    0
    ·
    14 days ago

    I just run whatever db is required in the docker compose stack. I’ve thought about running separate db like mongo, mysql, sqlite and having them as central db services for the containers. I don’t see a downside to doing that. It just seems to me that it’s easier just to run what is required by the compose stack itself. For what I’m doing, they don’t seem to eat up much resources.

    • mertn@lemmy.world
      link
      fedilink
      English
      arrow-up
      0
      ·
      12 days ago

      I do the same. If the docker container has problems with db I can just shut it down and fix the db from my desktop then start docker again. That has saved me starting again from scratch several times.

  • ser@lemmy.zip
    link
    fedilink
    English
    arrow-up
    0
    ·
    14 days ago

    Am having problem getting MariaDB to work with NextCloud. Any help would be appreciated.

    • darcmage@lemmy.dbzer0.com
      link
      fedilink
      English
      arrow-up
      0
      ·
      14 days ago

      Start a new thread with your compose file (minus the sensitive stuff). I’d be happy to take a look and I’m sure others will step in as well.

  • cecilkorik@lemmy.ca
    link
    fedilink
    English
    arrow-up
    0
    ·
    14 days ago

    I use a single centralized database running directly on the host (postgres) and make it accessible to the docker clusters.

    Pros: It’s all in one place to backup all important data for every service, I find this a much easier and more reliable way to backup all services, and I’m confident if you tried it you would too. The application data becomes a first-class citizen instead of hiding inside some nameless docker volume. Significantly less database overhead. Consistent database version and tools.

    Cons: Lots. You need to manage and backup the database. You need to manage the database users and passwords too. Making the DB accessible to the docker clusters is nontrivial and can be fragile. You can no longer use the default “official” docker compose files, since they will almost never support an actual database service without several modifications, they’re always built for spinning up their own docker container database. So you’re going to be doing a bunch of work setting up users and passwords and performing extensive surgery on the docker-compose before you even start up the application, which adds a lot of friction, with lots of opportunity for error. All things considered, it’s actually quite painful. Technically if one application abuses your database hard enough and exhausts its memory to crash it or something it would affect other applications too, but that’s true of any services running on shared hardware abusing anything on that hardware, so it’s not a realistically concerning con.

    I consider it worthwhile, but I might be wrong. Also I hate docker in general. I understand why people use it. It’s the same reason I use it. But I still hate it. I think system installations are so much easier to manage in the long run, but initially more work, and you need to invest that work at a time when you’re not even sure if you really want to run this application or if it’s going to be compatible with the rest of your environment. So docker is the easy solution. But then you’re basically trapped in dockerland. It’s not that bad, I just hate it in principle. I wish there were a better way.

    • tburkhol@slrpnk.net
      link
      fedilink
      English
      arrow-up
      0
      ·
      14 days ago

      I started doing the One True Database method because I got worried that the high write count on all the little db’s was abusing a raspberry pi’s SD card. Moved them all to a bigger server with NVME and mirroring to a RAID.

      Not all the compose files make obvious how to reconfigure the db host. Homeassistant uses s a sqlite db built into the container, rather than a separate unit, but you can force it to use a remote db through its config file. May or may not be worth hiding db user/pass in a .env And sometimes there’s trouble restarting after power failure, depending on what order the database, pi, and various containers come back up.

      I also feel it’s worthwhile. I feel better being able to check on all the databases. Feel better not writing to the SD card so much. Feel better offloading those megabytes and cpu cycles from the little pi. It’s been fun snooping through database structures. There have been a couple times where I decided to query one of the ccontain databases directly, or cross from one project to another, and it’s easier (for me) to give a different user privileges to the database and query some deep bit of data than to figure out how to extract it from an API or frontend.

      I’m not even running that many services, but why would I want the overhead of 6 separate mysql instances when I could just have one?

      • ohulancutash@feddit.uk
        link
        fedilink
        English
        arrow-up
        0
        ·
        14 days ago

        sometimes there’s trouble restarting after power failure, depending on what order the database, pi, and various containers come back up.

        depends_on solves this problem

  • Appoxo@lemmy.dbzer0.com
    link
    fedilink
    English
    arrow-up
    0
    ·
    12 days ago

    Not a database admin nor expert nor experienced. I also don’t want to experience dependency hell.
    Each service get’s what it requests in the readme/docker compose template.

  • IratePirate@feddit.org
    link
    fedilink
    English
    arrow-up
    0
    ·
    14 days ago

    One per service. Not just because it’s easy, but because it allows you to minimise blast radius. If you’re running one DB per container and one container gets compromised, only that one DB is compromised. With one centralised DB for all containers, a breach of one container means access to the data of all containers that use this database without the need for any lateral movement.

  • NGram@piefed.ca
    link
    fedilink
    English
    arrow-up
    0
    ·
    14 days ago

    I too spin up a new DB for every service that needs one. It makes maintenance less intrusive since I only have to shut down one service at a time to update or do a full file backup and I can safely tweak the DB config to best suit the service without worrying about negatively impacting other services on the same DB. I also like the flexibility to choose the best DB for the service, e.g. I use Postgres for a lot of the services I develop but they do also support MySQL/MariaDB, but I have other services that are more tested on MariaDB.

    I’d imagine having one database for everything could eventually cause performance problems across all services if the database gets too big or clunky or queries get too complex, even if just one service is causing the problem.

    I also run a lot of physical servers (I have about 10 low power computers I use as servers right now) so having a dedicated DB per service allows me to get better performance since the DB can be on the same machine as the service. Not that they need high performance, but it also helps with the efficiency.

  • clifmo@programming.dev
    link
    fedilink
    English
    arrow-up
    0
    ·
    13 days ago

    Bare metal database VM running mariadb, postgres and valkey. Haven’t had any issues with needing multiple versions. Simpler to manage imaging the VM and data backups from a central place. Plus, I need a general database anyways for development work, sanitized production clones, etc. No sense in having 50 database servers running when I can have 3

  • Consti@lemmy.world
    link
    fedilink
    English
    arrow-up
    0
    ·
    14 days ago

    I typically have one DB service per app service (not just ler cluster, unless multiple services need the same db).

    Advantages:

    • Simple backup/data organization, each service is self-contained
    • True isolation: Unless you manually create DB accounts for each service, likely all your services have access to all data, and even with accounts there are data leaks and exploits

    Disadvantages:

    • You have more services running than strictly needed, but this is a minuscule impact on performance (the overhead of the DB service is typically not noticable)
  • Daniel Quinn@lemmy.ca
    link
    fedilink
    English
    arrow-up
    0
    ·
    14 days ago

    I’ve had a really hard time figuring out how to get cloud native pg working 'cause I couldn’t get longhorn working for disk space.

    So instead I went with a separate Raspberry Pi that isn’t part of the cluster to host a single Postgres instance.

    It’s inelegant, but has worked for years. Still, I’d rather host a separate pg instance for each project… I just have to figure the above out first.

  • Decronym@lemmy.decronym.xyzB
    link
    fedilink
    English
    arrow-up
    0
    ·
    edit-2
    13 days ago

    Acronyms, initialisms, abbreviations, contractions, and other phrases which expand to something larger, that I’ve seen in this thread:

    Fewer Letters More Letters
    LXC Linux Containers
    NAS Network-Attached Storage
    NFS Network File System, a Unix-based file-sharing protocol known for performance and efficiency
    RAID Redundant Array of Independent Disks for mass storage
    SSD Solid State Drive mass storage

    5 acronyms in this thread; the most compressed thread commented on today has 7 acronyms.

    [Thread #13 for this comm, first seen 15th Jun 2026, 07:30] [FAQ] [Full list] [Contact] [Source code]

  • Zikeji@programming.dev
    link
    fedilink
    English
    arrow-up
    0
    ·
    14 days ago

    Individually. If the app requires a DB, I put it in the compose file. This simplifies both backups and migrations. My tooling for backups has a pre and post script I can customize on a per app basis so I just have the pre do whatever *dump for that DB and the post clean it up (backup takes a tar of the folder).

    • mertn@lemmy.world
      link
      fedilink
      English
      arrow-up
      0
      ·
      12 days ago

      My backup tooling just shuts down the container and associated db, then rysncs it all somwhere safe and restarts the container. Am I missing somethoing critical by not doing a db dump in the middle of that?

      • Zikeji@programming.dev
        link
        fedilink
        English
        arrow-up
        0
        ·
        12 days ago

        Most of the time that’s perfectly fine, but if the database were in the middle of an operation you risk corruption.

        • mertn@lemmy.world
          link
          fedilink
          English
          arrow-up
          0
          ·
          12 days ago

          The last thing I want is database corruption. That is why I “docker compose down” before I make a backup then “docker compose up” when the backup is complete. Is that not good enough? Do I have to do something else?