1 download

Download mirror

$ docker pull mongo:4.2.0
Copy the code

2 start

After startup, use port 27017 to connect to the database

$ docker run -v /var/docker/mongo:/data/db --name mongodb -e MONGO_INITDB_ROOT_USERNAME=root -e MONGO_INITDB_ROOT_PASSWORD=123456 -p 27017:27017 -d mongo:4.2.0
Copy the code

When using Docker Desktop to install Mongo under Windows10, the mapping directory is not supported, and the startup error is reported

Failed to start up WiredTiger under any compatibility version. Reason: 1: Operation not permitted Fatal Assertion 28595 at src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp 783

Just cancel the directory mapping and expect a later version to solve this problem.