docker 安装 mongodb
创建目录
mkdir -p /mongodb/data
拉取镜像
docker pull mongo
创建容器
docker run -d --name mongo --restart=always -v /mongodb/data:/data/db -p 27017:27017 --privileged=true mongo:latest
进入容器
docker exec -it mongo mongo admin
创建账号
db.createUser({ user:'admin',pwd:'root',roles:[ { role:'userAdminAnyDatabase', db: 'admin'},"readWriteAnyDatabase"]});
ivys-MBP:docker txp$ mkfile -p ./mogodb mkfile: illegal option -- p usage: mkfile [-nv] size[b|k|m|g] filename ... ivys-MBP:docker txp$ mkdir -p ./mongodb ivys-MBP:docker txp$ ls mongodb nacos redis ivys-MBP:docker txp$ cd mongodb/ ivys-MBP:mongodb txp$ ls ivys-MBP:mongodb txp$ mkfile -p data mkfile: illegal option -- p usage: mkfile [-nv] size[b|k|m|g] filename ... ivys-MBP:mongodb txp$ mkdir -p data ivys-MBP:mongodb txp$ docker pull mongo Using default tag: latest latest: Pulling from library/mongo d7bfe07ed847: Pull complete 97ef66a8492a: Pull complete 20cec14c8f9e: Pull complete 38c3018eb09a: Pull complete ccc9e1c2556b: Pull complete 593c62d03532: Pull complete 1a103a446c3f: Pull complete be887b845d3f: Pull complete e5543880b183: Pull complete Digest: sha256:37e84d3dd30cdfb5472ec42b8a6b4dc6ca7cacd91ebcfa0410a54528bbc5fa6d Status: Downloaded newer image for mongo:latest docker.io/library/mongo:latest ivys-MBP:mongodb txp$ docker run -d --name mongo --restart=always -v /Users/txp/docker/mongodb/data:/data/db -p 27017:27017 --privileged=true mongo:latest 6dd9ab531aa17e977ae4c37dff1bb28de426e4de58f4def8d5ad44df540a7696 ivys-MBP:mongodb txp$ docker exec -it mongo mongo admin MongoDB shell version v5.0.9 connecting to: mongodb://127.0.0.1:27017/admin?compressors=disabled&gssapiServiceName=mongodb Implicit session: session { "id" : UUID("c2b4394e-0e4e-44f4-be96-b187119d0070") } MongoDB server version: 5.0.9 ================ Warning: the "mongo" shell has been superseded by "mongosh", which delivers improved usability and compatibility.The "mongo" shell has been deprecated and will be removed in an upcoming release. For installation instructions, see https://docs.mongodb.com/mongodb-shell/install/ ================ Welcome to the MongoDB shell. For interactive help, type "help". For more comprehensive documentation, see https://docs.mongodb.com/ Questions? Try the MongoDB Developer Community Forums https://community.mongodb.com --- The server generated these startup warnings when booting: 2022-06-16T04:32:47.593+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted --- --- Enable MongoDB's free cloud-based monitoring service, which will then receive and display metrics about your deployment (disk utilization, CPU, operation statistics, etc). The monitoring data will be available on a MongoDB website with a unique URL accessible to you and anyone you share the URL with. MongoDB may use this information to make product improvements and to suggest MongoDB products and deployment options to you. To enable free monitoring, run the following command: db.enableFreeMonitoring() To permanently disable this reminder, run the following command: db.disableFreeMonitoring() --- > db.createUser({ user:'admin,pwd:'admin',roles:[{role:'userAdminAnyDatabase',db:'admin'},"readWriteAnyDatabase"]}); uncaught exception: SyntaxError: missing } after property list : @(shell):1:33 > db.createUser({ user:'admin',pwd:'root',roles:[ { role:'userAdminAnyDatabase', db: 'admin'},"readWriteAnyDatabase"]}); Successfully added user: { "user" : "admin", "roles" : [ { "role" : "userAdminAnyDatabase", "db" : "admin" }, "readWriteAnyDatabase" ] } >