Self-host Node-RED with Docker Compose
Flow-based low-code tool for wiring together devices, APIs and online services.
The steps below take a few minutes end to end.
Requirements
You'll need these installed on the machine you're deploying to:
Docker
Packages Node-RED and everything it depends on into an isolated container, so it runs the same way on your machine as it does everywhere else.
Install guideDocker Compose
Reads docker-compose.yml and starts everything in it together. Ships with Docker Desktop. On Linux servers it's usually a separate install.
Install guide1. Docker compose setup and file
Create a folder for Node-RED and save the file below into it as docker-compose.yml. It describes every container the stack needs — Node-RED itself and any supporting services, such as its database — along with the ports, volumes and environment variables each one uses. You'll also need an empty .env file in the same folder; Docker Compose reads it automatically and uses it to fill in the ${VARIABLE} references you'll see in the file below.
docker-compose.yml
version: "3.9"
services:
node-red:
image: nodered/node-red:latest
restart: unless-stopped
ports:
- 1880:1880
environment:
HOME: /data
NODE_RED_ADMIN_PASSWORD: ${SETUP_ADMIN_PASSWORD}
NODE_RED_ADMIN_USERNAME: admin
NODE_RED_CREDENTIAL_SECRET: ${RANDOM_NODE_RED_CREDENTIAL_SECRET}
NPM_CONFIG_CACHE: /data/.npm
volumes:
- data:/data
- tmp:/tmp
configs:
- source: node-red-settings.js
target: /etc/node-red/settings.js
command:
- node
- /usr/src/node-red/node_modules/node-red/red.js
- --userDir
- /data
- --settings
- /etc/node-red/settings.js
volumes:
data: null
tmp: null
configs:
node-red-settings.js:
content: |
const crypto = require("crypto");
function sameString(a, b) {
const left = Buffer.from(String(a));
const right = Buffer.from(String(b));
return left.length === right.length && crypto.timingSafeEqual(left, right);
}
module.exports = {
flowFile: "flows.json",
flowFilePretty: true,
credentialSecret: process.env.NODE_RED_CREDENTIAL_SECRET,
uiPort: 1880,
adminAuth: {
type: "credentials",
users: function (username) {
if (username === process.env.NODE_RED_ADMIN_USERNAME) {
return Promise.resolve({ username: username, permissions: "*" });
}
return Promise.resolve(null);
},
authenticate: function (username, password) {
if (
sameString(username, process.env.NODE_RED_ADMIN_USERNAME) &&
sameString(password, process.env.NODE_RED_ADMIN_PASSWORD)
) {
return Promise.resolve({ username: username, permissions: "*" });
}
return Promise.resolve(null);
},
},
logging: {
console: { level: "info", metrics: false, audit: false },
},
// No anonymous usage reporting, and no first-login prompt asking about it.
telemetry: { enabled: false },
editorTheme: {
projects: { enabled: false },
tours: false,
},
};
Volumes
Node-RED stores its data in named Docker volumes, so it survives container restarts and updates:
- data mounted at /data: Node-RED's user directory: flows, encrypted credentials, installed node packages and project files.
- tmp mounted at /tmp: Temporary working files.
2. Secret generation
Node-RED needs a few randomly generated secrets — for example, database passwords or an internal session key — before it can start. These are referenced from docker-compose.yml above but don't live in it, so they need to end up in your .env file. Pick one of the two options below.
Generating secrets…
3. Start Node-RED with Docker Compose
From the folder with docker-compose.yml and .env, run:
Terminal
Start Node-RED and all its supporting services in the background.
docker compose up -dThe -d flag runs the stack in the background so it keeps running after you close the terminal. Docker will pull the images the first time, which can take a minute or two.
To check on it afterwards: docker compose ps shows whether containers are healthy, and docker compose logs -f follows their logs if something looks wrong. Once it's running, open http://localhost:1880 in your browser.