Skip to content

Instantly share code, notes, and snippets.

@IliasDeros
Last active December 16, 2022 21:54
Show Gist options
  • Save IliasDeros/9d23f55173e6487ecb681caabf596923 to your computer and use it in GitHub Desktop.
Save IliasDeros/9d23f55173e6487ecb681caabf596923 to your computer and use it in GitHub Desktop.
Run mongodb in memory on Docker without using TMPFS (https://github.com/docker-library/mongo/issues/224)
import { MongoMemoryServer } from 'mongodb-memory-server';
// This will create an new instance of "MongoMemoryServer" and automatically start it
const mongod = await MongoMemoryServer.create({
instance: {
port: 27017,
ip: "::,0.0.0.0",
dbName: 'in_memory'
}
});
const uri = mongod.getUri();
console.log("Running in-memory MongoDB on " + uri);
FROM node:16
RUN apt-get install libcurl4
WORKDIR /project
COPY ./db.mjs /project
RUN yarn add mongodb-memory-server
ENTRYPOINT ["node", "./in-memory-db.mjs"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment