start mongodb 4.4 in docker,use ~/mongo/data to persist data
docker-compose.yml
version: '3.1'
services:
mongodb:
image: mongo:4.4
command: mongod --auth
volumes:
- ~/mongo/data:/data/db
ports:
- 27017:27017
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: {username}
MONGO_INITDB_ROOT_PASSWORD: {password}