Mariadb master-slave replication

Hi All,

I am trying to create a Mariadb master-slave replication in docker swarm with docker-compose. My goal is to have a redundant DB server with two different external storages( one for the master and one for the slave) in order to prevent data lost in case of storage failure.
I have tried with the following yml, but when I create a table on the master, it is not transferred to the slave:

version: '3.9'
services:
  db-master:
    image: mariadb:latest
    container_name: db-master
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: pass
      MYSQL_DATABASE: db
      MYSQL_USER: user
      MYSQL_PASSWORD: userpass
    volumes:
      - ./master/my.cnf:/etc/mysql/my.cnf
      - ./master/:/var/lib/mysql
    command: --log-bin=mysql-bin --server-id=1
  db-slave:
    image: mariadb:latest
    container_name: db-slave
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: pass
      MYSQL_DATABASE: db
      MYSQL_USER: user
      MYSQL_PASSWORD: userpass
    volumes:
      - ./slave/my.cnf:/etc/mysql/my.cnf
      - ./slave/:/var/lib/mysql
    command: --log-bin=mysql-bin --server-id=2 --slave-skip-errors=all --skip-slave-start

Here is the my.cnf master:

[mysqld]
server-id = 1
log-bin = mysql-bin
binlog_format = ROW

Slave my.cnf:

[mysqld]
server-id = 2
relay-log = mysql-relay-bin
log-slave-updates = 1
replicate-do-db = db

Could you please help me understand what the problem could be?

Any help will be appreciated!

In order to solve this, you need to know how repication works with MariaDB and I have never configured MariaDB replication manually yet. I am not sure if I configured it at all. Log messages could tell you more about the issue if there is any log about this. If you have a link to a documentation or a blogpost thatyour work was based on, someone can try to check if you followed that correctly. Otherwise it is a MariaDB replication issue and not really a Docker issue.

If you have already configured MariaDB replication correctly without containers, please share how you have done it so we can help you how it should be done with Docker. (unless someone already knows that and helps recognize the issue just by looking at your config.

What I can tell you is that when you work with swarm, you should use configs instead of bind mounts

so it can be shared with all of the hosts in case you are working with multiple nodes and not on the one where you run the docker command.