How I can copy a file in the volume with Dockerfile

Hi, I’m trying to copy a local file into the a volume using dockerfile copy

COPY --from=builder Database.db /mnt/Database

but I got an error

Error failed to fetch an image or build from source: error building: failed to compute cache key: "/Database.db" not found: not found

Hi @Jeffer-arevalo

You’ll need to add the db file to your Dockerfile, then create a script that copies the file to /mnt/Database ( if it doesn’t already exist ) before it starts your app process. Something like this entrypoint should work.

Dockerfile:

COPY --from=builder Database.db /tmp/

Script:

if [ ! -f /mnt/Database/Database.db ]; then
...
  cp /tmp/Database.db /mnt/Database/Database.db
...
fi
...
1 Like