How to upload an initial SQLite DB to a volume before deploy


I am currently trying out with a small remix app, which uses a SQLite db.
I might want to look into lite-fs at some point, but for now I am fine with having my app running in a single location, which means I should be a able to use volumes to persist my db.

I have created a new app and a volume for it. But now I can not figure out how to put my existing SQLite db on the volume. Essentially I am looking for a way to upload the database before my first deployment.

I though I could use something like fly ssh sftp for it, but that results in a Error no instances found for <app-name> error. It looks like I need to deploy first before using the command, but that does not make sense, since my app relies on the database being there.

What is the best way to upload the db to a volume before my first app deploy?

Hi Hnnng,

The first thing that comes into mind is to deploy a dumb application based on some Linux Docker image, mount the volume according to docs in fly.toml:


Change the volume data using fly ssh sftp and deploy your applications after that.

1 Like

Thanks! That worked!

How do you transfer the volume to a new machine where the application image is deployed onto? Can you elaborate on it a little bit? Thanks!


Figured it out! Initialize volume with local data · GitHub · GitHub

#!/usr/bin/env bash
set -euo pipefail

YOUR_APP=""     # eg. my-app
YOUR_VOL=""     # eg. app-data
YOUR_REGION=""  # eg. hkg
LOCAL_PATH=""   # eg. /tmp/data/*
REMOTE_PATH=""  # eg. /data/

echo 'Run this script after fly launch and fly vol create. C-c to abort.'

# spin up tmp
fly machine run -r ${YOUR_REGION} -v ${YOUR_VOL}:${REMOTE_PATH} --entrypoint "tail -f /dev/null" alpine -n tmp
id=$(fly m ls | awk 'NR==6 {print $1}')
ip=$(fly m ls | awk 'NR==6 {print $6}')

# connect to tmp - proxy
fly proxy 10022:22 ${ip} -a ${YOUR_APP} &
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
sleep 3

# connect to tmp - key
[ -f ~/.ssh/fly ] && rm -f ~/.ssh/{fly,}
fly ssh issue personal ~/.ssh/fly --hours 1

# copy to tmp
ssh -o "StrictHostKeyChecking=no" \
    -o "UserKnownHostsFile=/dev/null" \
    -p 10022 -i ~/.ssh/fly root@localhost "apk add openssh-client"
scp -o "StrictHostKeyChecking=no" \
    -o "UserKnownHostsFile=/dev/null" \
    -P 10022 -i ~/.ssh/fly -r ${LOCAL_PATH} root@localhost:${REMOTE_PATH}

# destroy tmp
fly machine destroy --force ${id}