title: How to solve MySQL database data disappear in Docker Swarm
body: <p>When I use docker swarm with MySQL I met with problem (If docker container rerun mysql data will disappear)</p>
  <p>I  spend a lot of time to search how to fix this problem,  use volume store data and use glusterFs across host share volume but experiencing database data inconsistency.</p>
  <p>Is my method right ? or can someone tell we how to fix this problem?</p>
  <p>At last , This is my example yaml file :</p>
  <pre><code>version: '3.8'
  services:
    www:
      image: httpd:latest
      ports: 
      - &quot;8001:80&quot;
      volumes:
      - /usr/papertest/src:/var/www/html/  
    
  
    db:
      image: mariadb:latest
      restart: always
      volumes:
      - /usr/test/src:/docker-entrypoint-initdb.d
      - /etc/timezone:/etc/timezone:ro
      - /usr/test/backup:/var/lib/mysql  #/usr/test/backup is  glusterfs mount place
  
      environment: 
        MYSQL_ROOT_PASSWORD: MySQL_PASSWORD
        MYSQL_DATABASE: MYSQL_DATABASE
        #MYSQL_USER: MYSQL_USER
       # MYSQL_PASSWORD: MYSQL_PASSWD
  
      
  
    phpmyadmin:
      image: phpmyadmin
      #restart: always
      ports:
      - 4567:80
      environment:
      - PMA_ARBITRARY=1
  </code></pre>