Attempting to save database information on host machine

I’ll start by saying I’m sure I’m doing something wrong. Docker is new to me.

I have a web app that saves information into a sqlite database. When I deploy this app, it takes data and puts it into tables. Fairly simple. However I’m trying to mount a volume to be able to access the information that gets saved when the container is running for later access. Here is my file structure of the host computer:

   |_lots of other files and folders

I would like the data to be saved in the /home/bp15630/data folder. However when I try to create a volume to that directory, it doesn’t work or doesn’t save.

The following command does work, but it’s not saving where I want it. Obviously the file is in New_Monthly_Report/database so it obviously works.

docker run -it -v /home/bp15630/New_Monthly_Report/database:/app/database -p 5000:5000 --name monthly_report monthly_report

I also tried

docker run -it -v /app/database:/home/bp15630/data -p 5000:5000 --name monthly_report monthly_report

but also no luck.

Any help to try to get the database saved to where I’d like would be much appreciated! Thanks!

Assuming that you have the right permission for the specific directory, try the following command:

docker run -it -v /home/bp15630/data:/app/database -p 5000:5000 --name monthly_report monthly_report

In this command, you are mapping the host directory /home/bp15630/data to the container directory /app/database. This should allow you to save the database to the desired host directory.

So I have tried that direction but I get an error that my table names don’t exist.

Connecting to the database and not finding the tables or not being able to save the file where you want it are two different problems. First make sure that the file is where you expect it to be and second, try to connect to it properly.

If you have the file at the right place, please share how you write data into it and how you try to read it. I don’t see how that could be related to Docker, but we can check it for you.

I have the folder structure shown in my initial post. So it should be there if the correct connection is

docker run -it -v /home/bp15630/data:/app/database -p 5000:5000 --name monthly_report monthly_report

Unless I need to do:

docker run -it -v /home/bp15630/data:/New_Monthly_Report/database -p 5000:5000 --name monthly_report monthly_report

but my Dockerfile has the working directory as /app.

I’ve been reading and writing data into it using functions and sql queries within the app. Do you want to see some of those? I have existing ‘starter’ data and tables when the app is written into a container.

Don’t just guess the syntax. If you are not sure how volumes and bind mounts work, start to “play” with these options and create test containers until you understand it if the documentation isn’t clear enough.

However, @ajeetraina gave you the perfect answer regarding the mount syntax. Left side is the source on the host, right side is the destination inside the container.

If you want to change the folder names that is up to you.

I don’t “want to” :slight_smile: but I offer my help and I can’t tell you what you did wrong unless I can see what you did. It may be that you used a wrong filename when you wanted to wrote the database and read it from another file. If you can show me some code how you try to connect, I might be able to recognize a mistake but ther eis no guarantee and I feel the original question was answered. The rest of the issue is most likely a programming issue not related to Docker.

There were permission issues within the virtual machine and Docker that got ironed out with my boss. Thanks for the help.