[英]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. 我有一个python烧瓶REST应用程序,它在部署时创建一个.db sqlite数据库文件。 This application is now deployed on three node docker swarm cluster.
此应用程序现在部署在三节点docker swarm群集上。 I use a swarm-stack file to deploy the container on those nodes.
我使用swarm-stack文件在这些节点上部署容器。 My problem is now each container has its own .db file ie a separate database for each instance of the application.
我的问题是现在每个容器都有自己的.db文件,即每个应用程序实例的单独数据库。 I want a common mount point for this db file so that each service should access a common database.
我想要这个db文件的公共挂载点,以便每个服务都应该访问一个公共数据库。 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 . 在整个节点/机器上共享文件不是Docker直接为您解决的问题,但您可以在共享存储系统的上下文中查看Docker存储驱动程序。 This helps it integrate with solutions such as NFS, ZFS, etc.
这有助于它与NFS,ZFS等解决方案集成。
However, you mentioned that you're using SQLite and Flask, using the SQLAlchemy driver. 但是,您提到您正在使用SQLite和Flask,使用SQLAlchemy驱动程序。 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.
为了避免让您头疼,而不是尝试在三个节点之间共享文件系统,您应该使用数据库服务器,例如MySQL , MariaDB或PostgreSQL (仅举几例),所有这些都适用于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.
这样,您可以让所有Flask容器连接到同一个数据库容器,而不是尝试与Flask应用程序的所有正在运行的实例共享相同的SQLite文件(这将经常/快速锁定/降级)。
This extra database can be easily run within a container and also managed by docker-compose
. 这个额外的数据库可以在容器中轻松运行,也可以通过
docker-compose
管理。 This way, only one node needs access to the filesystem to store data for the database. 这样,只有一个节点需要访问文件系统来存储数据库的数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.