Question

Can I use a sqlite database on app-platform

Hi, I have a simple python flask app that is creating and writing to a sqlite database (this creates a mydb.db file in the filesystem). I know if I would use “droplet” this would not be a problem but I was wondering if I could also use “app-platform”…I think I don’t because it will run in a docker container that will not persist filesystem changes right ? I tested it with a simple app and it worked (theres no error that I cant write to the filesystem or something like that) so now I’m wondering am I correct that I should not use sqlite with app-platform, and if so, in what situation would the containers restart/wipe the filesystem could it happen “any time” or only when performing some administrative work like changing the scaling plan ?

Also if I cant use sqlite can you point me to resources how to integrate digitaloceans hosted db

Thanks in advance, I’m new to web dev and digitalocean seams really nice.


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

You are correct that using SQLite with DigitalOcean App Platform may not be the best choice because the file system in the containers used by App Platform is not persistent. Containers in App Platform are designed to be ephemeral, meaning they can be restarted or scaled up/down at any time, and any changes made to the local file system within a container will be lost when the container is replaced or restarted.

SQLite relies on a local file to store its data, and if you use it within an App Platform container, you risk losing your data whenever the container is restarted or replaced. Therefore, for production applications, it’s generally recommended to use a more robust and scalable database system, such as PostgreSQL or MySQL, which can be easily integrated with DigitalOcean’s managed database services.

To integrate DigitalOcean’s hosted database service with your Flask app on App Platform, you can follow these general steps:

  1. Create a Managed Database: In your DigitalOcean account, create a managed database instance. You can choose either PostgreSQL or MySQL based on your preference and requirements.

  2. Database Connection: Retrieve the connection details for your managed database, including the host, port, username, and password.

  3. Update Application Configuration: In your Flask application, update the database configuration to use the connection details from the managed database. You will typically need to modify the database URL or connection string in your Flask app’s configuration to point to the managed database.

    For example, if you’re using SQLAlchemy in your Flask app, you can configure it like this:

    pythonCopy code from flask_sqlalchemy import SQLAlchemy app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://username:password@host:port/database_name' db = SQLAlchemy(app)

  4. Deploy to App Platform: Push the updated code to your App Platform repository, and configure the environment variables for your managed database connection details. These environment variables can typically be set in your App Platform app’s settings.

  5. Deploy Your App: Deploy your Flask app to DigitalOcean App Platform. It will now use the managed database for storing and retrieving data.

  6. Test: After deployment, test your application to ensure that it’s properly connected to the managed database and functioning as expected.

By following these steps, you can use a managed database with DigitalOcean App Platform, ensuring data persistence and scalability for your web application.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel