Zabbix setup swarm

Hello , im facing this error everytime i try install zabbix with docker compose usin swarm and docker stack , but when i lunch docker-compose up everything works fine , but when i use docker stack deploy everytime i got errors like : unable to setup database , or existing table , or user error

1- docker compose file :

version: “3.9”
networks:
zbx_net:
driver: overlay

services:
zabbix-server:
image: zabbix/zabbix-server-mysql:ubuntu-5.2-latest
deploy:
mode: replicated
replicas: 3
environment:
DB_SERVER_HOST: mysql-server
MYSQL_DATABASE: zabbix
MYSQL_USER: zabbix
MYSQL_PASSWORD: Securi123
ports:

  • “10051:10051”
    depends_on:
  • mysql-server
  • zabbix-java-gateway
    networks:
  • zbx_net

mysql-server:
image: mysql:8.0
deploy:
mode: replicated
replicas: 3
environment:
MYSQL_ROOT_PASSWORD: Securi123
MYSQL_DATABASE: zabbix
MYSQL_USER: zabbix
MYSQL_PASSWORD: Securi123
ports:

  • “3306:3306”
    networks:
  • zbx_net

zabbix-web:
image: zabbix/zabbix-web-apache-mysql:ubuntu-5.2-latest
deploy:
mode: replicated
replicas: 3
environment:
DB_SERVER_HOST: mysql-server
MYSQL_DATABASE: zabbix
MYSQL_USER: zabbix
MYSQL_PASSWORD: Securi123
PHP_TZ: Asia/Shanghai
ZBX_SERVER_HOST: zabbix-server
ports:

  • “80:8080”
  • “443:8443”
    depends_on:
  • mysql-server
  • zabbix-server
    networks:
  • zbx_net

zabbix-agent:
image: zabbix/zabbix-agent:ubuntu-5.2-latest
deploy:
mode: replicated
replicas: 3
environment:
ZBX_SERVER_HOST: zabbix-server
ports:

  • “10050:10050”
    depends_on:
  • zabbix-server
    networks:
  • zbx_net

zabbix-snmptraps:
image: zabbix/zabbix-snmptraps:ubuntu-5.2-latest
deploy:
mode: replicated
replicas: 3
ports:

  • “162:1162/udp”
    networks:
  • zbx_net

Please reformat your post according How to format your forum posts.

Also, please let me know how you configured mysql to replicate database state between the container replicas.

Adding replicas to a service does not work if the application inside the containers are not configured to use a shared state, have build-in replication or some sort of consensus, except when the application is compeletly stateless and/or stores state only in a database.

Hello, i just write the compose file with zabbix needed services , mysql i added env settings like host , user password , when i lunch with docker compose up d everything works fine except when i use docker stack deploy i have issues

Container orchestration and Cloud providers make it easy to run replicas of services, but they DO NOT solve how these services are replicated and synchonize a global state. The service must support replcation by itself and needs to be configured properly to actually be used with it replica instances.

So, please let me understand how you replicate database state amongst the replica instances.
If this is not solved, then each database replica will have a different state, as if you run 3 distinct databases, that just happen to be reachable by the same service vip (think of it as a load balancer in front of the replica instances)

I will explain what i did :
1-i installed 2 vms through hyper v (one will be manager and second act like worker ) i want make HA , when a server is down the other starts

2- i set docker swarm init in first server
3- i joined the second server with docker swarm join
4- i found a compose file with (zabbix server + web interface+ mysql or pgsql + zabbix agent )
5- in compose file when i write in mysql service i set replicas = 1 or 2 its always the same problem

Please format your post, it still does not use preformated text blocks for the compose file content.

So you run every service with a single replica?
Then there shouldn’t be a problem, unless of course the compose file you found itself doesn’t configure everything properly.