How is mariadb supposed to be used with multiple containers?

Hi

I’m a little confused by how mariadb is supposed to be set up. If you have multiple containers that need mariadb, are you supposed to fire up a standalone mariadb container with its own separate docker-compose.yml, or include a separate instance of mariadb in each of the container stacks which need it?

I’m confused because MYSQL_DATABASE/USER/PASSWORD are configured in the compose. For example, Nextcloud wants a ‘ncsuer’ account, and pydio-cells wants a ‘root’ account. So if I started a standalone mariadb instance, how is this supposed to be set up?

So method A)

docker-compose for mariadb
docker-compose for nextcloud (pointing to existing mariadb)
docker-compose for pydio-cells (pointing to existing mariadb)

Or method B)

docker-compose for nextcloud, mariadb
docker-compose for pydio-cells, mariadb

If method A (which makes more logical sense to me), what are the config files supposed to look like to wire this all up correctly? I would imagine that the /config/env files may come into play here, but the docs don’t really get into any specifics about this situation.

Thank you :smiling_face:

the compose options can create 1 database for you. you can run muiltiple mariadb containers if you like or simply create additional databases inside a single mariadb like you normally would (it works the same as a non-containerized mariadb)

Thank you. I’m not actually very familiar with mariadb.

or simply create additional databases inside a single mariadb

This is what I’d prefer to do honestly. Can this be done entirely through compose files or do I need to manually configure databases? If I created a standalone mariadb compose like this:

---
version: "2.1"
services:
  mariadb:
    image: ghcr.io/linuxserver/mariadb
    container_name: mariadbshared
    environment:
      - PUID=1001
      - PGID=1001 <-- should other user accounts running containers be added to this group?
      - MYSQL_ROOT_PASSWORD=abc123
      - TZ=Europe/London
    volumes:
      - /home/sharedaccount/mariadb:/config
    restart: unless-stopped
networks:
  default:
    external:
      name: sharednetwork

Could a hypothetical Nextcloud compose look something like this?

---
version: "2.1"
services:
  nextcloud:
    image: lscr.io/linuxserver/nextcloud
    container_name: nextcloud
    environment:
      ...
    depends_on:
      - mariadbshared
    restart: unless-stopped
  mariadb:
    container_name: mariadbshared
    environment: 
      - PUID=1001 <--- should this be the nextcloud user added to a db group?
      - PGID=1001 <--- should this be the db group? 
      - MYSQL_ROOT_PASSWORD=abc123
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=ncuser
      - MYSQL_PASSWORD=somefancypassword
    volumes:
      - /home/sharedaccount/mariadb:/config
    restart: unless-stopped
networks:
  default:
    external:
      name: sharednetwork

Am I way off on this? I’ve been searching around… and maybe my search terms just suck, but I can’t find a whole lot of examples of how to do this properly.

Ideally I would like one mariadb container, and point all the other containers to it, without having to manually create all the databases and users with queries. If I can’t do that, then I guess I’d probably just add a new maria container instance to each stack that needs it

I’m a bit new to all of this. Pardon my ignorance

Our mariadb container can only create one database via env vars. Others would have to be manually created.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.