Windows 10系统,安装的Docker Desktop。
docker-compose.yml文件内容如下:
(提示:yml文件对文件格式有严格要求,包括空格的使用)
version: '3'
services:
mongo:
image: mongo:5.0.8
container_name: mongo
restart: always
ports:
- "27017:27017"
command: --auth
volumes:
- ./initdb:/docker-entrypoint-initdb.d
- ./datadir:/data/db
- ./configdb:/data/configdb
environment:
MONGO_INITDB_ROOT_USERNAME: dbadmin
MONGO_INITDB_ROOT_PASSWORD: 123456
MONGO_INITDB_DATABASE: logdb
TZ: Asia/Shanghai
mongo-express:
image: mongo-express:0.54.0
container_name: mon-express
restart: always
ports:
- "8081:8081"
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: dbadmin
ME_CONFIG_MONGODB_ADMINPASSWORD: 123456
TZ: Asia/Shanghai
Power Shell中执行:
docker-compose up -d
执行成功以后,yml文件同目录下,会自动产生3个文件夹,MongoDB的数据文件也在其中。
通过浏览器访问Mongo Express:http://127.0.0.1:8081/?
?
?
|