I have some questions about disk space and usage. I have a sqlite app with a static file database (sqlite) and when I start the app I mount this as a volume to my Docker image.
docker run -v ./data:/mnt my_image
I’m trying to understand how to accomplish this using fly deploy.
First, I’m curious which directory the app files are mounted when I use a Dockerfile in my app deployment. Then I can tell my app in the container to use that volume to start itself.
Second, I’m wondering how much disk space does fly give me in the free tier? My app isn’t big, but I could need a 1GB-2GB of disk storage.
If you name it data, you can add this to your fly.toml to do the equivalent of your Docker volume:
[mount]
source = "data"
destination = "/mnt"
Running instances use 5GB volumes, but these do not persist between reboots. You could copy your sqlite file elsewhere periodically and pull it down to the instance at boot time, but it’s not built in.
I added a volume and tried the [mount] clause, but it didn’t work. I think the error message was "/mnt already exists."
The issue isn’t creating or using a volume, but adding the local database to the volume from the commandline. How do I put the sqlite database into a volume without going through the webapp? The webapp needs the file to be there – otherwise it won’t start.
It’s a little bit of a pain to get data onto a volume for the first time, you’ll need to add it to your Dockerfile, then create a script that copies the file to /mnt if it doesn’t already exist before it starts your app process.
It’s a datasette app. It’s fine to add the db to the image for now, which is what I did, but it limits the functionality because, as you said, the db won’t persist between restarts, and the app will need to be read-only.
So basically, you’re saying the first time I deploy I copy the db to the volume, and the next time I change the ENTRYPOINT and use the volume mount instead. I think that would work. But it’d be great if there was a cleaner solution.
Yes, although you don’t necessarily have to change the entrypoint between deploys. Here is an entrypoint we use to do some extra logic if there are files missing:
You could do that same kind of if block to copy the sqlite file from a temp Docker Image path to the mounted volume path.
Are you trying to mount a volume at /tmp? It’s probably best to mount to a different location, almost every Docker image already has a tmp directory (and we can’t mount over an existing directory).
rm: cannot remove ‘/tmp/v8-compile-cache-0/8.4.371.23-node.67/zSoptzSyarn-v1.22.5zSbinzSyarn.js.BLOB’: Permission denied
rm: cannot remove ‘/tmp/v8-compile-cache-0/8.4.371.23-node.67/zSoptzSyarn-v1.22.5zSbinzSyarn.js.MAP’: Permission denied
unfortunately that did not work, could try removing it from my app
Changed my docker image, added tmp to the docker ignore file, added rm /app/tmp to my docker file, removed the tmp file from my app, but I still see:
directory /app/tmp already exists
Thinking about this more it’s probably being created during the asset compilation.
Ideally I would like to mount the public folder or tmp but I could live without for this app, I could just mount a random folder to pin the app to a region