Running Node-RED on Google Cloud Platform under Docker
It’s very easy to run Node-RED on a GCP.
If you’ve not used Google Cloud Platform before, start here. Otherwise, assuming you have a project [[PROJECT-ID]] and have the Cloud SDK installed, let’s start by defining some environment variables:
NODE=[[NODE-NAME]] # e.g. "node-red"
ZONE=[[ZONE]] # e.g. "us-east1-d"
CONTAINER_FILE=[[CONTAINER-FILENAME]] # e.g. "node_red.yaml"
To make things simplest, we’re going to run Node-RED in Docker on the VM. We provide a configuration file to GCP with the command to create the VM.
Create a file called whatever you’ve decided for [[CONTAINER_FILE]] and use the following text for its content. This tells GCP where to find the Docker image for Node-RED and to run it on port 1880:
- name: node-red
- containerPort: 1880
Now, to create a VM running Docker, with Node-RED installed and configured using the [[CONTAINER_FILE]], use the following command:
gcloud compute instances create $NODE \
When the command completes and the VM is created, it will summarize the VM details including the EXTERNAL_IP address. Keep a record of this EXTERNAL_IP address as it is the IP address you will use to browse to Node-RED. You may also find the EXTERNAL_IP for your NODE with this command:
gcloud compute instances list \
In order to access the Node-RED VM from other machines, you must open the firewall for port 1880. Use this command:
gcloud compute firewall-rules create allow-node-red \
--allow tcp:1880 \
You should now be able to visit Node-RED using the following URL. Replace EXTERNAL_IP with the IP address that you determined previously:
And, then with the “first flow” deployed:
To delete the VM and delete the firewall, use the following commands:
gcloud compute instances delete $NODE \
gcloud compute firewall-rules delete allow-node-red \
It’s very easy to run Node-RED in a container on a VM in Google Cloud Platform. Have fun!