# Persistant data SQLite when running docker image

**URL:** <https://discourse.nodered.org/t/persistant-data-sqlite-when-running-docker-image/85971>\
**Category:** General\
**Tags:** docker, sqlite\
**Created:** [27 February 2024 20:44 UTC](https://discourse.nodered.org/t/persistant-data-sqlite-when-running-docker-image/85971 "2024-02-27T20:44:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![hadwll](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hadwll/32/89020_2.png) [@hadwll](https://discourse.nodered.org/u/hadwll)\
**Post date:** [27 February 2024 20:44 UTC](https://discourse.nodered.org/t/persistant-data-sqlite-when-running-docker-image/85971/1 "2024-02-27T20:44:12Z")

</div>

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

```auto
    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

```auto
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?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/d/3d925eb702ed81df64a7b7f7541a399e33cbd7e3.png)

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [27 February 2024 21:17 UTC](https://discourse.nodered.org/t/persistant-data-sqlite-when-running-docker-image/85971/2 "2024-02-27T21:17:06Z")

</div>

> [@hadwll](#):
>
> 27 Feb 20:18:19 - [error] [sqlitedb:ab1d8188a18f1722] failed to open /data/sqlite

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`

> [@hadwll](#):
>
> is there a correct way to save the data in a volume so that it persists?

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](https://github.com/node-red/node-red-docker?tab=readme-ov-file#using-a-host-directory-for-persistence-bind-mount))

---

<div class="post-metadata">

**Author:** ![hadwll](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hadwll/32/89020_2.png) [@hadwll](https://discourse.nodered.org/u/hadwll)\
**Post date:** [28 February 2024 05:32 UTC](https://discourse.nodered.org/t/persistant-data-sqlite-when-running-docker-image/85971/3 "2024-02-28T05:32:28Z")

</div>

> 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?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/f/0f2f4b9dd1ff4ae4f3187485299b5516f002bb70.png)

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [28 February 2024 08:18 UTC](https://discourse.nodered.org/t/persistant-data-sqlite-when-running-docker-image/85971/4 "2024-02-28T08:18:04Z")

</div>

> [@hadwll](#):
>
> 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

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.

---

<div class="post-metadata">

**Author:** ![hadwll](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hadwll/32/89020_2.png) [@hadwll](https://discourse.nodered.org/u/hadwll)\
**Post date:** [28 February 2024 20:24 UTC](https://discourse.nodered.org/t/persistant-data-sqlite-when-running-docker-image/85971/5 "2024-02-28T20:24:45Z")

</div>

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/](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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/8/6847951c5d05a1c8bdd35776727699146d1a4f13.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [28 February 2024 20:52 UTC](https://discourse.nodered.org/t/persistant-data-sqlite-when-running-docker-image/85971/6 "2024-02-28T20:52:42Z")

</div>

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).

> [@hadwll](#):
>
> 28 Feb 05:31:15 - [info] [sqlitedb:4d1a20893d84e686] opened /tmp/sqlite ok

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.

---

<div class="post-metadata">

**Author:** ![hadwll](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hadwll/32/89020_2.png) [@hadwll](https://discourse.nodered.org/u/hadwll)\
**Post date:** [28 February 2024 21:14 UTC](https://discourse.nodered.org/t/persistant-data-sqlite-when-running-docker-image/85971/7 "2024-02-28T21:14:28Z")

</div>

sorry I picked you up the wrong way round.

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/6/e6d0dc07b950ee4f8dd6d91edaa6b28fb0a6f8a6.png)

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

> docker exec -it e0f5436ff790 bash

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/3/b398d7acc91b03aad7a84805fbaddea0a29a2729.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/b/4b308409512ca423480c548410d9942c55bbf0b3.png)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [13 March 2024 21:15 UTC](https://discourse.nodered.org/t/persistant-data-sqlite-when-running-docker-image/85971/8 "2024-03-13T21:15:13Z")

</div>

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