docker-compose部署mongodb6.0.1单机

创建mongodb.conf配置文件:

# mongod.conf

# for documentation of all options, see:

#   http://docs.mongodb.org/manual/reference/configuration-options/

# Where and how to store data.

storage:

  dbPath: /data/db

  journal:

    enabled: true

#  engine:

#  wiredTiger:

# where to write logging data.

systemLog:

  destination: file

  logAppend: true

  path: /data/logs/mongod.log

# network interfaces

net:

  port: 27017

  bindIp: 0.0.0.0

# how the process runs

processManagement:

  timeZoneInfo: /usr/share/zoneinfo

#security:

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options:

#auditLog:

#snmp:

需要注意路径和docker映射的路径一致。

创建docker-compose.yml

version: "3.9"

services:

  mongodb:

    image: mongo:6.0.1

    container_name: mongodb

    restart: unless-stopped

#    command: [--auth]

    privileged: true

    environment:

      - TZ=Asia/Shanghai

      - MONGO_INITDB_ROOT_USERNAME=root

      - MONGO_INITDB_ROOT_PASSWORD=xxxxxx

    ports:

      - "27017:27017"

    volumes:

      - /data/mongedb/data:/data/db

      - /data/mongedb/logs:/data/logs

      - /data/mongedb/config:/etc/mongo

    command: mongod --config /etc/mongo/mongod.conf

 启动前检查各目录和文件是否创建,然后启动镜像:

用navicat连接成功:

docker-compose部署mongodb6.0.1单机_第1张图片

 

你可能感兴趣的:(docker,mongodb,容器)