Currently there is no easy method and out-of-box option to automatically start MariaDB + Galera with automatic cluster bootstrapping.
Galera requires a bootstrap phase that are provided by the galera_new_cluster script for the systemd or calling manually the service mysql bootstrap command for the SysVinit. Both cases requires manual actions. Also this approach will not work with environments without systemd and SysVinit like Docker containers.
Current workaround for the MariaDB container to automatically run Galera cluster with automatic cluster bootstrapping is to create a special wrapper for the mysqld daemon and set the GALERA_NEW_CLUSTER=1 environment variable for the first container in the cluster:
The one-shot bootstrapping is provided by the first if statement. Galera during the cluster creation creates the /var/lib/mysql/gvwstate.dat file. This file is used for auto-detecting that cluster was already bootstrapped by the --wsrep-new-cluster option.
- Please add an optional argument to the --wsrep-new-cluster option for the mysqld daemon like for example once (or one-shot) that will implement this logic. Example: mysqld --wsrep-new-cluster=once
- Without arguments it will behave like before (default, always bootstrap)
- Additional always argument for explicit invocation (like without arguments, default, always bootstrap)
- Add supports for a new environment variable MARIADB_NEW_CLUSTER that will allow to pass once or always (default) arguments for the --wsrep-new-cluster option
This should not only simplify running Galera cluster in multi container scenario but in other scenarios also.