It's typical to mount a volume for your DB so the data persists. I typically use docker-compose as it's easier to execute and maintain. I was able to get this working but I had to modify a docker-compose file and modify the mongod configuration file change in the container to enable mongodb authentication.
I'm currently evaluating nodebb and discourse for use by a client. The config change I made won't be persistent as I modified the file in the running container. That's obviously not the correct way to solve the problem.
In case it's helpful, here's the docker-compose I used:
version: '3.5'
services:
node:
image: nodebb/docker
restart: unless-stopped
depends_on:
- db
ports:
- "4567:4567"
db:
image: mongo:bionic
restart: unless-stopped
ports:
- "27017:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: root
volumes:
- bbdata:/data/db
volumes:
bbdata:
And here's a link that helps understand the mongod.conf file changes:
https://medium.com/mongoaudit/how-to-enable-authentication-on-mongodb-b9e8a924efac
Additionally, when running the web installer for nodebb, you'll need to tell it the database is at the host specified in the docker-compose (e.g. 'db'), not localhost.