Search code examples
dockergoogle-cloud-storagegoogle-cloud-runnode-red

How to create persistent docker containers on google cloud run instance?


Context

I need to use an instance of node-red in the cloud so that it can be shared among several users and to use it additionally for communication via http endpoint with other local node-red instances, I chose to deploy this instance on google Cloud Run.

Problem

Everything works correctly until I make changes to the flow of the node-red instance placed on google cloud run. As soon as Cloud Run restarts the changes disappear and therefore all the work is not retained, I would like to find a way for this not to happen and for the changes I apply to the stream to be retained.

More context

Using a dockerfile, I defined a docker container image of an instance of node-red. Below is the code I used:

FROM nodered/node-red
WORKDIR /data
COPY package.json /data
RUN npm install --unsafe-perm --no-update-notifier --no-fund --only=production
WORKDIR /usr/src/node-red
COPY settings.js /data/settings.js
COPY flows_cred.json /data/flows_cred.json
COPY flows.json /data/flows.json

as defined in the node-red documentation. I then pushed the built image to Google artifact registry and then deployed it on Google Cloud Run. As described above, everything works correctly except that the stream information I created/edited is not saved and at each new access in Cloud Run the Node-red instance re-initialises.

I know that Cloud Run started out as a serverless service but I found these resources provided by google that indicate the possibility of mount a storage system to it via google cloud bucket. I followed the guide, yet even after re-deploying the google cloud run instance, the problem remains.


Solution

  • You have 2 choices.

    1. find a way to mount a persistent volume on the /data directory when the container is run. That way any files (including the flows.json) will be saved and should be available when the container restarts. You didn't say in your question where you mounted the google cloud bucket.

    2. Update the settings.js file to use a different storage plugin. The default plugin uses the json files stored in the /data directory, but you can either write your own or use one of the existing ones that will store the data elsewhere, e.g. there are several that can be used to store things in a database or somewhere like AWS S3