ustcweizhou / docker-mariadb-cluster

MariaDB Galera Cluster in Docker Containers. Find images at https://hub.docker.com/r/ustcweizhou/mariadb-cluster
7 stars 6 forks source link

deploy in swarm with portainer #4

Open devMls opened 2 years ago

devMls commented 2 years ago

Hi

at first, this is just the thing that i was looking for, amazing work.

i am trying to deploy with portainer in a 3 nodes docker swarm this solution, i edit the yaml file but i have some errors, i can fix the depends_on but with the external files, i don't know where to push it. i am using deploy stack option.

i have this error:

open /data/compose/24/nginx-galera.conf: no such file or directory

and three questions:

version: "3.8"
services:
  db01:
    image: ustcweizhou/mariadb-cluster:latest
    hostname: db01
    networks:
        overlay-db:
    volumes:
      - ${DATA_DIR}/$PROJECT/db01:/var/lib/mysql
    healthcheck:
        test: ["CMD", "mysqladmin", "-uroot", "-pcloudstack", "ping"]
        interval: 10s
        timeout: 10s
        retries: 60
        start_period: 10s
    environment:
      - NODE_NAME=db01
      - CLUSTER_ADDRESS=gcomm://db01,db02,db03
      - DB_ROOT_PASSWORD=cloudstack
      - DB_MARIABACKUP_PASSWORD=cloudstack
    deploy:
      placement:
        constraints:
          - "node.labels.node==docker1"
  db02:
    image: ustcweizhou/mariadb-cluster:latest
    hostname: db02
    depends_on:
      - db01
    networks:
        overlay-db:
    volumes:
      - ${DATA_DIR}/$PROJECT/db02:/var/lib/mysql
    healthcheck:
        test: ["CMD", "mysqladmin", "-uroot", "-pcloudstack", "ping"]
        interval: 10s
        timeout: 10s
        retries: 60
        start_period: 10s
    environment:
      - NODE_NAME=db02
      - CLUSTER_ADDRESS=gcomm://db01,db02,db03
      - DB_ROOT_PASSWORD=cloudstack
      - DB_MARIABACKUP_PASSWORD=cloudstack
    deploy:
      placement:
        constraints:
          - "node.labels.node==docker2"    
  db03:
    image: ustcweizhou/mariadb-cluster:latest
    hostname: db03
    depends_on:
      - db01 
      - db02
    networks:
        overlay-db:
    volumes:
      - ${DATA_DIR}/$PROJECT/db03:/var/lib/mysql
    environment:
      - NODE_NAME=db03
      - CLUSTER_ADDRESS=gcomm://db01,db02,db03
      - DB_ROOT_PASSWORD=cloudstack
      - DB_MARIABACKUP_PASSWORD=cloudstack
    deploy:
      placement:
        constraints:
          - "node.labels.node==docker3"
  dbvip:
    image: nginx
    hostname: dbvip
    networks:
        overlay-db:
    ports:
        - "13306:3306"
    deploy:
      restart_policy:
        condition: on-failure
    configs:
        - source: nginx-galera
          target: /etc/nginx/nginx.conf
    depends_on:
      - db01

configs:
    nginx-galera:
        file: ./nginx-galera.conf

networks:
    overlay-db:
        driver: overlay
        attachable: true
        ipam:
            driver: default
            config:
                - subnet: 192.168.10.0/24
weizhouapache commented 2 years ago

@devMls thanks for raising this issue.

I have not verified yaml by docker swarm in the past 2 years. so there might be some bugs. could you please create a pull request if you have fixed some issues you faced ?

If this docker image does not fit you want, you can modify the conf file or init.sh and rebuild the docker image. for example

  1. change the conf in my.cnf or create a conf file in conf/ (they will be copied when you rebuild the docker image)
  2. replace nginx with proxysql in yaml
  3. create a script for backup and copy it to docker image (see init.sh)

hope it helps.