1
0
mirror of https://github.com/vimagick/dockerfiles.git synced 2024-12-25 02:04:06 +02:00

update mongo

This commit is contained in:
kev 2021-12-01 11:31:58 +08:00
parent 2c3aaff6b0
commit ac617d603c
2 changed files with 33 additions and 40 deletions

View File

@ -3,48 +3,24 @@ mongo
[MongoDB][1] is an open-source, document database designed for ease of development and scaling.
## docker-compose.yml
```yaml
mongo:
image: mongo
command: --auth
container_name: mongo
ports:
- "27017:27017"
restart: always
```
## up and running
```bash
$ pwgen -1 8 2
pah4Xa0o
$ pwgen -1 8 1
Aedahwa7
$ cd ~/fig/mongo/
$ docker-compose up -d
$ docker exec -it mongo bash
/# mongo
> use admin
> db.createUser({user: 'root', pwd: 'pah4Xa0o', roles: [{role: 'userAdminAnyDatabase', db: 'admin'}]})
> db.auth('root', 'pah4Xa0o')
> db.runCommand({usersInfo: 1})
> exit
/# exit
$ docker cp mongo:/usr/bin/mongo /usr/local/bin/
$ mongo mongodb://root:pah4Xa0o@localhost:27017/admin
> use mydb
> db.createUser({user: 'myuser', pwd: 'Aedahwa7', roles: [{role: 'readWrite', db: 'mydb'}]})
> exit
$ mongo mongodb://root:root@localhost:27017/admin
>>> use mydb
>>> db.createUser({user: 'myuser', pwd: 'Aedahwa7', roles: [{role: 'readWrite', db: 'mydb'}]})
>>> exit
$ mongo mongodb://myuser:Aedahwa7@localhost:27017/mydb
> show collections
> exit
>>> show collections
>>> exit
```
Read [this][2] and [this][3] for more help.

View File

@ -1,9 +1,26 @@
mongo:
image: mongo
command: --auth
container_name: mongo
ports:
- "27017:27017"
volumes:
- ./data:/data/db
restart: always
version: "3.8"
services:
mongo:
image: mongo:5
ports:
- "27017:27017"
volumes:
- ./data:/data/db
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: root
restart: unless-stopped
mongo-express:
image: mongo-express
ports:
- "8081:8081"
environment:
ME_CONFIG_MONGODB_URL: mongodb://root:root@mongo:27017
ME_CONFIG_BASICAUTH_USERNAME: admin
ME_CONFIG_BASICAUTH_PASSWORD: admin
depends_on:
- mongo
restart: unless-stopped