Добавить пользователя admin
db.createUser( { user: "admin", pwd: "adminPassword", roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] } )
Контейнер
version: '2.4' services: agis-mongo-db: image: "mongo:6.0.3" container_name: agis-mongo-db hostname: agis-mongo-db command: [--auth] volumes: - ./agis-mongo-db/db:/data/db ports: - "31300:27017" restart: on-failure cpus: 2 mem_limit: 10gb healthcheck: test: ["CMD","mongosh", "--eval", "db.adminCommand('ping')"] interval: 10s timeout: 10s retries: 5 start_period: 40s networks: default: external: name: agis-net
Как узнать версию mongodb
Первый вариант:
$ docker exec agis-mongo-db bash -c "mongod --version"
db version v4.4.1
Build Info: {
"version": "4.4.1",
"gitVersion": "ad91a93a5a31e175f5cbf8c69561e788bbc55ce1",
"openSSLVersion": "OpenSSL 1.1.1 11 Sep 2018",
"modules": [],
"allocator": "tcmalloc",
"environment": {
"distmod": "ubuntu1804",
"distarch": "x86_64",
"target_arch": "x86_64"
}
}
Второй вариант
$ docker exec -it agis-mongo-db mongo MongoDB shell version v4.4.1 connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb Implicit session: session { "id" : UUID("007a6d89-d038-40ee-b89b-d11aa243ac87") } MongoDB server version: 4.4.1 Welcome to the MongoDB shell. > db.version() 4.4.1