In the example above, the āshared-dataā volume is permanent storage shared by both services serviceOne and serviceTwo bound to the /shared path for both. service-one-data is only available to serviceOne, bound to the /private path, and service-two-data is only available to serviceTwo, bound to the /private path. In effect, there are three permanent storage volumes, one shared by both, and two private volumes.
Hope this helps, if you still have questions, please let us know!
I read the documentation that you shared and a discussion on the balena forum #22
It cleared some concepts but I still have some doubts. Now I have a database file that I want to persists through all container update and changes.
First Question =>
Where should I add the database to persist it? and How can I add it?
Second Question =>
What I understood from the above 2 links is that using balena volume ls I can confirm if the volume is loaded. But I am confused about How docker compose file should be constructed for that purpose?
volumes:
Test-Database: {}
service-1:
volumes:
- 'Test-Database': #what should be added here?
Question 3 =>
what should I pass the database path in my application code?
As stated in the docs āNamed volumes can be given arbitrary names and can be linked to a directory in one or more containersā. So you are linking the volume youāve created to a named directory in your container:
is not correct and does not conform to the docker-compose specification or the examples above. As noted in both Docker and balena documentation, everything is in quotes and is the path of a directory, not a file:
- 'Test-Database:/usr/src/app/app1/database'
(note also that in your file tree the database directory appears to be in lower case)
But suppose I have a file which is dynamically created when running the Application and I want to persists that How can I add that to the persistent storage in that case?
Hi @Sharvin26, in the dockerfile you are linking a directory used by your service (in the container) to a persistent volume in the host OS (outside of the container). Then in your application code, what you write under this linked directory persists over application and host OS updates. You donāt need to specify a file name in the docker compose file. Itād work fine as long as you write your files under that linked directory.
In your case, when you setup the database in one of your services, you could specify that this database is written on persistent storage. Heds linked an example how this is done with influxdb.
Where is this file supposed to be located @Sharvin26?
Perhaps you could post some code and we could take a look. In general, being a container should not affect something so mundane as writing to a logfile.
Hi all.
Iāva just one more question to add to this topic (but escuse me if my question is a dumb question ).
It is possible to directly create a volume on an unmounted drive (like a USB stick on the host),ā¦something like :
ā volumes:ā
ā - āshared-data:/dev/sda1ā
ā¦ ord do we have to mount it before on the host, or maybe create a container that mount the USB on its filesystemā¦ and expose it to others containers ā¦
Hi.
I am trying to find the best way to share an USB stick of my host BalenaOS ?
-can i mount it directly on my balenaOS (using FASTAB, or maybe a startup srcipt)
-do i have to mount it on a āData COntainerā and share to to others container via Volumes ?
Iāve maybe just find a good way to do this using the udevrules in the json.config ?
ā¦ but what I didnāt try out (like you suggested) is to mount it in a data container and share it to other containers via Volumes. I think that is certainly worth a try. So for that I would create a subfolder in that volume and mount the drive to that subfolder.
If that doesnāt work, you can also mount it in one container and share it via nfs to the other containers.
Whaouuuā¦ thank you for you answerā¦and yours projects are a plenty of usefull information .
I agree with you, i think il will mount the usb stick on a mount point on a containe, and share it with others through NFS.
I can alos answer you question, sharing this mountpoint through a Volume doesnt work ! Because ONLY the first container wich have the mount point is seeing data from the USB stickā¦others just see an empty Volume.
Thank for you help
PS : i will test it very soon because it is a working configuration, nut in a second time il will continue my searc in order to mount it on the Host OSā¦ in fact i am fearing maybe about performances issues) ā¦ did you face some performances issues on your setup ?
1/ Have you tried by first creating a subfolder in the volume and then mounting it to this subfolder ? I would at least expect that the other containers see this subfolder.
2/ Regarding performance issues. It all depends on the amount of data you want to read/write to the USB stick and the type of USB stick.