Home:ALL Converter>Docker Swarm Persist DB Data

Docker Swarm Persist DB Data

Ask Time:2022-04-22T01:40:35         Author:Evan Lalo

Json Formatter

I've seen variations of this question but for some reason I think I'm missing something.

Problem

I'm running a couple of containers on docker swarm. Every time my DB container, or backend container restarts, the database gets cleared. I thought that volumes were supposed to prevent this from happening.

This is how I created my swarm and the containers.

docker swarm init

docker network create --driver overlay network
docker volume create -d local --name mysql_data

docker service create --name db \
    --replicas 1 \
    --env MARIADB_ALLOW_EMPTY_ROOT_PASSWORD="yes" \
    --env-file ../server/.env \
    --network network \
    --mount source=mysql_data,destination=/var/lib/mysql/data/ \
    mariadb:10.7.3

docker service create --name django \
    --replicas 1 \
    --env CONTAINER="True" \
    --env-file ../server/.env \
    --network network \
    --with-registry-auth \
    client_backend:deploy

docker service create \
    --name frontend \
    --replicas 1 \
    --network network \
    -p 8080:80 \
    --with-registry-auth \
    client_frontend:latest

Am I mounting my volume wrong or is there something else I'm missing?

Thanks,

Author:Evan Lalo,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/71958726/docker-swarm-persist-db-data
Chris Becke :

The docker "local" volume driver is just that. It creates volumes on each nodes local file system.\nTo get persistent storage that is swarm aware you have several options:\nIf you are using something like a PureStorage SAN you can use their Trident docker volume plugin which is swarm aware. Rancher 1 could also build swarms with persistent volume support.\nOtherwise you can roll your own persistent network storage using nfs or glusterfs servers. With nfs there is a syntax to create the volume using the local driver but with nfs options and credentials, and docker will mount the nfs volume on each node the service is deployed onto.\nWith glusterfs there are some community docker volume plugins of varying quality levels, or you can just mount a big /mnt/gfs/docker mount on each host and just use bind mounts from each container/service that needs persistent storage.",
2022-04-21T18:11:45
yy