简体   繁体   中英

How to mount a common sqlite database file for python flask application running on three node docker-swarm cluster?

I have a python flask REST application which when deployed creates a .db sqlite database file. This application is now deployed on three node docker swarm cluster. I use a swarm-stack file to deploy the container on those nodes. My problem is now each container has its own .db file ie a separate database for each instance of the application. I want a common mount point for this db file so that each service should access a common database. How can I implement this? I am new to docker.

Sharing files across entire nodes/machines isn't something Docker will directly solve for you, but you can take a look at Docker storage drivers in the context of shared storage systems . This helps it integrate with solutions such as NFS, ZFS, etc.

However, you mentioned that you're using SQLite and Flask, using the SQLAlchemy driver. To save you a huge headache, rather than trying to share a filesystem across your three nodes, you should use a database server such as MySQL , MariaDB , or PostgreSQL (to name a few), all which work well with SQLAlchemy. That way, instead of trying to share the same SQLite file with all running instances of your Flask app (which will lock/degrade very often/quickly), you can have all of your Flask containers connect to the same database container.

This extra database can be easily run within a container and also managed by docker-compose . This way, only one node needs access to the filesystem to store data for the database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM