How to create persistent docker containers on google cloud run instance?
08:54 06 Jun 2024

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.

docker google-cloud-storage google-cloud-run node-red