How may I mount a tmp ram drive via Dockerfile.template?

Hello balena gurus,
I’m working on a “quick” security camera with Raspberry Pi 3 and/or Pi Zero Wireless. Captured images will be temporarily stored in RAM and qualified before writing to SSD. The intent to not burn out the micro-sd card with lots of image writes while checking for image changes (saving the ones that detect motion).

How would I accomplish this with balena.io? In the past, I think I followed this quick guide:
https://www.domoticz.com/wiki/Setting_up_a_RAM_drive_on_Raspberry_Pi

sudo mkdir /var/tmp
sudo nano /etc/fstab
# add:
tmpfs /var/tmp tmpfs nodev,nosuid,size=64M 0 0
sudo mount -a

Here’s where I’m at so far in the Dockerfile.template (just getting started):

FROM balenalib/%%BALENA_MACHINE_NAME%%-node

RUN apt-get -q update && \
apt-get install -yq --no-install-recommends build-essential libraspberrypi-bin \
apt-get clean

# Hmmm where to start with new tmp RAM drive...

COPY package.json /package.json
RUN npm install

COPY src/ /usr/src/app
CMD ["node", "/usr/src/app/index.js"]

Thanks for taking a look in advance! :smiley:

Hey there! The base image you are using is Debian based, therefore you should be able to use any tmpfs mount point defined by Debian OS out of the box, and then moved them to a named volume for persistent storage

Cool thanks! Is there an issue accessing this from the app? I suppose I should read up a bit more. I’m not quite sure how the app is running on top of the base. Reading up now. :slight_smile:

I think you might be able to define a tmpfs volume and mount it in your container. To figure out how to define it, see here: https://docs.docker.com/compose/compose-file/compose-file-v2/#long-syntax . Mounting the volume is described here: https://www.balena.io/docs/learn/develop/multicontainer/#named-volumes

Oh cool! I didn’t realize one could use docker-compose with balena.io. Catching up now…

Awesome! I think this does the trick:

version: '2'
volumes:
    # This RAM drive is for raspicam to place a constant stream of images while not
    # burning out MicroSD card, pending motion detection and move to image-ready.
    image-temp:
      driver_opts:
        type: tmpfs
        device: tmpfs
        # 128MB (in bytes)
        size: 134217728
    # Images are stored here when motion is detected, ready for upload when possible.
    image-ready:
services:
    raspicam-manager:
        build: ./raspicam-manager
        volumes:
            - 'image-temp:/image-temp'

I can see the drive mounted as a root folder named ‘/image-temp’ via the remote terminal while my starter script starts.

Thanks for your help! :grinning: :grinning: :grinning: