@klutchell, Thank you for the information and guidance. I feel I have learned a massive amount about all of this since I originally posted, but your post has been very helpful.
I have the following (untested) init.sh
script to mount the NVMe drive at boot of the container/device:
#!/env/bin bash
# UNTESTED!
mkdir -p /mnt/nvme
mount -t ext4 -o rw -L nvme /mnt/nvme
mkdir -p /mnt/nvme/postgres/data
exec docker-entrypoint.sh
with the following (untested) Dockerfile:
# UNTESTED!
FROM timescale/timescaledb:latest-pg13
ENV PGDATA=/mnt/nvme/postgres/data
ENV POSTGRES_PASSWORD=password123
ENV TIMESCALEDB_TELEMETRY=off
COPY init.sh /
RUN chmod +x /init.sh
ENTRYPOINT ["/init.sh"]
While I haven’t had a chance to test this yet, I believe I am on the right track based on the example in @klutchell’s NextCloud project. I will report back once I get a chance to test it.
I would like to note that this means only this container has access to the NVMe. Access from multiple containers is currently not supported, but based on the discussion in How to add persistent storage for Balena OS on Raspberry PI, it might be possible to partition the NVMe into separate partitions and mount each partition separately within each container. Once I get a single container working, I am going to try this as well.
Just in case someone else comes across this post. Some additional thoughts and details:
- I would like to clarify that Named Volumes are not needed for persistent storage when using an external drive. If the container is restarted or the device is restarted, the data will still be on the external drive and available to the container. Based on my reading of the documentation, both for Balena and Docker, this point is not very clear. External device storage is separate from Named Volumes.
- I had another idea to move the
/var/lib/docker/volumes
folder to the NVMe and then all Named Volumes would be stored on the larger, more stable (non-SD card) “external” drive. Moving the/var/lib/docker/volumes
folder appears to be very involved and possibly harmful to the OS. Using symbolic links can also cause errors. While this would make persisting storage on an external drive relatively straight-forward, it is basically a non-starter.