I am new to Docker and I want to do mini-project with Docker Swarm. I built docker image with my Django app. In dockerfile I added project files, migrated all models, and then ran server. Now it is time to prepare SQL database for django as a new service in stack. Now I am using only one replica build from MariaDB image. It has env vars needed to configure database, and mounted one local volume to store data on machine where container is running. In django settings I changed DB backend to mysql and DB host to name of database service. At this moment everything is working well.
But what If I want to have more replicas of DB engine? How should I deal with store data from diffrent nodes? If I use present configuration, data stored on first node won`t be the same as on second node.
And here is a question: How should I configure volume in compose-file to let all tasks use the same data.
I read some blogs and discussions where many people says, docker swarm is not good orchestrator to handle with DB, but is it really true?.
version: "3" services: django-site: image: questionsite:maria ports: - 8080:8080 deploy: replicas: 1 depends_on: - database networks: - site database: image: mariadb:latest ports: - 3306:3306 networks: - site deploy: replicas: 1 environment: MYSQL_HOST: "database" MYSQL_DATABASE: 'djangosite' MYSQL_USER: 'xxxx' MYSQL_PASSWORD: 'xxxxxx' MYSQL_ROOT_PASSWORD: 'xxxxx' MYSQL_ROOT_HOST: "%" MYSQL_PORT: "3306" volumes: - db_loc:/var/lib/mysql networks: site: external: true volumes: db_loc: driver: local