How to assure that a container is writing data to a USB disk drive connected to the device?

Context:

  • multi container application running on a raspberry pi with a USB disk drive connected to it.

Objective:

  • assure that data of the influxdb container gets written to the USB disk drive.

How can I achieve this ?

I know how I can define a named volume in the docker-compose.yml and assure that the influxdb data gets written to this named volume. But I don’t know how I can map this named volume to a USB disk drive that is connected to my raspberry pi.

I think that I should implement one of the solutions proposed in https://www.balena.io/docs/learn/develop/runtime/#mounting-external-storage-media

So I think this means that I cannot use named volumes, instead I need to add the necessary instructions in the influxdb Dockerfile so that it mounts the USB disk drive and that it changes the influxdb configuration so that the influxdb data is written to the mounted filesystem.

@janvda yes, for external storage, that is indeed the case (named volumes are sort of “virtual” storage areas, sharing the space with the containers, etc)

If you want to add external storage, I think that link you posted needs an update on our side (taking a not of it), as for multicontainer that is a bit out of date.

For the device to correctly show up in the container, I think you will need to add ENV UDEV=on (in the Dockerfile) in the container, and maybe also setting “privileged” label for that given service.
Once that’s done, you need to add your own method of mounting and using it, in the CMD step (ie. best is adding a start script, and calling that in the CMD step).

Let us know if you run into any issues!

1 Like

@imrehg Thanks for the update.
I managed to get it working. (see the configuration for the influxdb container in https://github.com/janvda/balena-node-red-mqtt-nginx-TIG-stack).

It would of course be much cleaner if I could define this external storage as a volume in my docker-compose.yml file. I guess for that the docker-compose.yml file needs to support the correct driver_opts.

So is it not possible to configure this in docker-compose.yml and if not are there plans to support these options in the near future ?

@janvda currently it’s not possible to add more complex volume definitions but we do plan to add it (and as supervisor maintainer, this will likely be added by me :slight_smile: ).

2 Likes