Deploying machines with sqlite db on a volume

I’m new to fly, and relatively new to both docker and sqlite.

I’m able to deploy my app, with a volume. The sqlite db is baked into the docker image (COPY orders.db /app/).

To create the volume using fly, I had to add to the toml:

[mounts]
  source="my_data"
  destination="/data"

I don’t want to use litefs (yet); I’m fine with the db being bound to the machine. However, it clearly needs to live on the volume rather than on the vm’s storage. So here are my questions:

  1. How do I move orders.db from the container’s /app directory to the volume? Is that the responsibility of my application?

  2. If the latter, is there a pattern I should follow for testing the docker container locally? Can I simulate the /data/ volume in my docker container within that clobbering fly’s volume mount?

Do you have to copy the local file into the docker image cause in typical setups this PITA? You don’t want your mutable data in your build artifacts.

You can just move it at /data/orders.db. For my own applications I usually just read from DATABASE_URL environment variable then I swap it out depending on whether I’m dev or in production.

That depends on whether you want to to keep the data around or not but that what docker volumes are for. You’re probably find better resources for how to configure your specific environment on the internet.

Do you have to copy the local file into the docker image cause in typical setups this PITA? You don’t want your mutable data in your build artifacts.

It’s just an empty template, not mutable data. However, obviously I don’t want to overwrite it.

Does fly have a recommended way to initialize a volume? If I could copy orders.db (blank) to the volume on application initialization, that would work. Obviously I can also init a new database if one doesn’t exist, but that seems a bit annoying.

but that what docker volumes are for

Fair enough.

That’s the way that’s documented in Persisting the Storage Folder · Fly Docs.

I posted a new wishlist item just now in Automatic volume initialization like in Docker, but I have no idea if or when Fly.io would be interested in implemeting that.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.