Persistant data SQLite when running docker image

I am running a docker image with the following familiar command;

    docker run -it -p 1880:1880 -v node_red_data:/data --name mynodered nodered/node-red

Each time I run the container the flows etc are all returned

I have setup a sqlliteDB that works quite well except it loses the data when I run the container/restart my machine, my path for the DB is tmp/sqlite so as that is not in a volume it is overwritten

I have tried a couple of things, running docker exec to go into the data folder and create a folder for a new SQlite DB it does not work I get the error ( this is almost certainly not the way to do this)

27 Feb 20:18:19 - [error] [sqlitedb:ab1d8188a18f1722] failed to open /data/sqlite

I have tried to add another volume to the docker container but it does not work either but the folder is in the container when I exec in

hadwll@documentholder:~$ docker exec -it 80ec65d5fa40 bash
80ec65d5fa40:~$ ls
entrypoint.sh  node_modules   package.json
80ec65d5fa40:~$ cd /data
80ec65d5fa40:/data$ ls
Logs               flows_cred.json    logfile1           package-lock.json  settings.js
flows.json         lib                node_modules       package.json       sqlite
80ec65d5fa40:/data$ cd sqlite
80ec65d5fa40:/data/sqlite$

is there a correct way to save the data in a volume so that it persists?

in that error /data/sqlite is a folder
did you specify an actual database filename in the sqlite node ?
for example : /data/sqlite/sqlite3.db

regarding this question i find it easier to use a Docker Bind Mount which is like mapping a host machine folder to your docker container's NR data folder. This makes it easier to backup the files instead of the Named Volume method. (more info here)

in that error /data/sqlite is a folder
did you specify an actual database filename in the sqlite node ?
for example : /data/sqlite/sqlite3.db

I did not specify it directly, in the setup node here is the original database entry it only requires the path, when the nodes are loaded then it creates the sqlite3.db file?

I tried adding the full name,

data/sqlite/sqlite.db3

and also adding it to the run command.

docker run -it -p 1880:1880 -v node_red_data:/data -v sqlite:/data/sqlite/sqlite3.db --name mynodered2 nodered/node-red

but get the error in the console

28 Feb 05:31:14 - [info] Starting flows
28 Feb 05:31:15 - [info] Started flows
28 Feb 05:31:15 - [error] [sqlitedb:444b55ef5e60fede] failed to open /data/sqlite/sqlite3.db
28 Feb 05:31:15 - [info] [sqlitedb:4d1a20893d84e686] opened /tmp/sqlite ok

I will check the bind mount, maybe it is an option for me.

Don't add sqlite to the docker command, you are putting the database in a folder inside /data, which is already mounted.
The reason it worked in /tmp is that there is not a folder called sqlite in there, so it created a file /tmp/sqlite for the database.

1 Like

this was today effort, still no dice..

hadwll@documentholder:~$ docker run -it -p 1880:1880 -v node_red_data:/data --name mynodered nodered/node-red
28 Feb 20:23:36 - [info]

Welcome to Node-RED

28 Feb 20:23:36 - [info] Node-RED version: v3.1.3
28 Feb 20:23:36 - [info] Node.js version: v16.20.2
28 Feb 20:23:36 - [info] Linux 5.15.0-97-generic x64 LE
28 Feb 20:23:36 - [info] Loading palette nodes
28 Feb 20:23:37 - [info] Dashboard version 3.6.2 started at /ui
28 Feb 20:23:38 - [info] Settings file : /data/settings.js
28 Feb 20:23:38 - [info] Context store : 'default' [module=memory]
28 Feb 20:23:38 - [info] User directory : /data
28 Feb 20:23:38 - [warn] Projects disabled : editorTheme.projects.enabled=false
28 Feb 20:23:38 - [info] Flows file : /data/flows.json
28 Feb 20:23:38 - [info] Server now running at http://127.0.0.1:1880/
28 Feb 20:23:38 - [warn]


Your flow credentials file is encrypted using a system-generated key.

If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.

You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.

28 Feb 20:23:38 - [info] Starting flows
28 Feb 20:23:38 - [info] Started flows
28 Feb 20:23:38 - [error] [sqlitedb:444b55ef5e60fede] failed to open /data
28 Feb 20:23:38 - [info] [sqlitedb:4d1a20893d84e686] opened /tmp/sqlite ok

Once again, you have to provide a file name for the database, not a folder. In your previous try you had the database as /data/sqlite/sqlite3.db which should be ok (assuming that you have a folder /data/sqlite).

That means that you still have a database config node pointing to the file /tmp/sqlite. In the menu dropdown Configuration Nodes you should see that that is unused and can delete it. That is not part of your problem though.

1 Like

sorry I picked you up the wrong way round.

in the node setup of sqlite3 the default is /tmp/sqlite

I added the file manually using exec docker exec and hey presto it works. Gift.

docker exec -it e0f5436ff790 bash

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.