Azure / iotedge

The IoT Edge OSS project
MIT License
1.45k stars 457 forks source link

Create a reusable Volume in Azure IOT Edge Module via Container Create Options #7265

Closed tcochunk closed 3 months ago

tcochunk commented 3 months ago

This is not so much a bug but more of a question. I have been searching for days but cant find anything.

The larger question is where can i find good documentation for the Container Create Options for an IOT Edge Module?

My very specific scenario is:

I have a module i created based on a third party database provider with the intent of pushing this database to my edge devices. Because its a database, I want the data to survive updates and my research says Volumes are the mechanism for doing that.

My current Container Create Options looks like this:

{ "Volumes": { "/data": {} } }

When I deploy the module, a volume is created with a generated name. If I modify the database the changes will persist across container restarts but if I deploy again, the changes are lost.

What options are available in the {}? What does "/data" mean? Where does this map to on the host? (the docker folder?) Can I specify the location on the host? Can I give this volume a name? How do I create a volume that can be reused by different versions of a module?

david-emakenemi commented 3 months ago

Hey @tchochunk, here are some good documentations that we have that covers how to configure container create options for IoT Edge modules and modules access to a device's local storage. Let us know if this helps.

tcochunk commented 3 months ago

@david-emakenemi thank you for the response. I read both those articles and if I copy the HostConfig section from modules access to a device's local storage and use that with my information, it does work. But I dont know what it does. After reading several sites, it seems that Volumes are better than binds but i cant find any documentation on implementing Volumes. While I have a working example, I dont have an understanding of what is happening and the 2 articles are focused on a very small subset of the options available.

I guess I am looking for additional documentation so I will keep searching. Sincerely, Thank You.

UPDATE: so i made some progress and my conclusion is to carefully read and study the documentation on the docker website https://docs.docker.com/engine/api/v1.30/#tag/Container/operation/ContainerCreate. After this post and following my own advice i came up with the following couple of solutions:

The following config will work (as @david-emakenemi referenced) and the data stored will survive container restarts and deploys: { "HostConfig": { "Mounts": [ { "Type": "bind", "Source": "/srv/db/data", "Target": "/data", "ReadOnly": false } ] } }

The following also works but creates a volume that maps to the docker managed location (/var/lib/docker/volumes). while i can specify the volume name i did not see a way to specify the source location. maybe i could make the volume separately and specify the location there and just reference that volume here??? { "HostConfig": { "Mounts": [ { "Type": "volume", "Source": "desiredVolumeName", "Target": "/data", "ReadOnly": false } ] } }