kriszyp / lmdb-js

Simple, efficient, ultra-fast, scalable data store wrapper for LMDB
Other
479 stars 39 forks source link

docker with read-only filesystem #271

Closed runk closed 2 months ago

runk commented 4 months ago

Hello, I noticed a problem with lmdb attempting to flush something to the disk, even when used with { readOnly: true } option. This is making it challenging to use it with AWS lambda which has read-only root file system.

Steps to reproduce

  1. Make a simple db using code from README.md
import { open } from 'lmdb'; // or require
let myDB = open({
    path: './db.lmdb',
});
await myDB.put('greeting', { someText: 'Hello, World!' });
  1. A test script, test.js
const lmdb = require('lmdb');

const db = lmdb.open('./db.lmdb', {
  readOnly: true,
  noSync: true,
});

const res = db.get('greeting');
console.log(res);
  1. Make a Dockerfile:
FROM public.ecr.aws/lambda/nodejs:20

RUN npm i lmdb
COPY test.js .
COPY db.lmdb .
COPY db.lmdb-lock .

ENTRYPOINT [ "node", "test.js" ]
  1. Build
docker build  -t lmdb .
  1. Run (with writable root fs - default)
    docker run lmdb

output:

{ someText: 'Hello, World!' }
  1. Run in read only mode
    docker run --read-only lmdb

output:

/var/task/node_modules/lmdb/dist/index.cjs:2626
        let rc = env.open(options, flags, jsFlags);
                     ^

Error: Read-only file system
    at Object.open (/var/task/node_modules/lmdb/dist/index.cjs:2626:15)
    at Object.<anonymous> (/var/task/test.js:3:17)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
    at node:internal/main/run_main_module:28:49 {
  code: 30
}
kriszyp commented 3 months ago

Should be fixed in v2.9.3 and v3.0.0.