如何使用新的守护进程标志重启现有的MongoDB Docker容器 [英] How to restart an existing MongoDB Docker Container with a new flags to daemon

查看:104
本文介绍了如何使用新的守护进程标志重启现有的MongoDB Docker容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  • 我有一个运行在服务器上的MongoDB实例,没有复制集标志(-replSet

  • 我以前在数据库中存储了一些信息,希望保留这些信息

  • I have a MongoDB instance running on a server without the replication set flag (--replSet)
  • I have some previously stored information on the Database and wish to retain the information

  • 我希望使用<$ c重新启动容器$ c>-replSet为守护程序设置的 my-set 标志,并保持先前​​的信息完整

  • I wish to however restart the container with the --replSet "my-set" flag set for the daemon and keep the previous information intact

我正在尝试遵循使用Docker在MongoDB中设置副本集并在我的本地计算机上试用副本集的教程。

I am trying to follow along a tutorial for setting replica sets in MongoDB with Docker and trying it out on my local machine.


  1. 创建一个标准的MongoDB Docker容器,不包含表示当前状态的标志 replSet 的设置:

docker run -d --name mongo_rs --publish 37017:27017 mongo


  • 使用MongoDB罗盘我已连接到数据库并添加了一些虚拟对象信息到名为 test 的数据库和名为 players

    我停止容器:

    docker container stop mongo_rs
    


  • 从这里开始,我要添加-replSet my-set mongo_rs 容器,并通过 mongo Shell配置副本集,如教程。实现它的可能解决方案是什么?

    From here onwards I wish to add the --replSet "my-set" to the mongo_rs container and configuring the Replica set via the mongo Shell as mentioned in the tutorial. What is the possible solution for achieving it?

    推荐答案

    这是我的.yml文件

    version: '3.7'
    
    services:
      node1:
        image: mongo 
        ports:
          - 30001:27017 
        volumes:
          - $HOME/mongoclusterdata/node1:/data/db 
        networks:
          - mongocluster
        command: mongod --replSet comments 
      node2:
        image: mongo
        ports:
          - 30002:27017
        volumes:
          - $HOME/mongoclusterdata/node2:/data/db
        networks:
          - mongocluster
        command: mongod --replSet comments
        depends_on :
          - node1 
      node3:
        image: mongo
        ports:
          - 30003:27017
        volumes:
          - $HOME/mongoclusterdata/node3:/data/db
        networks:
          - mongocluster
        command: mongod --replSet comments
        depends_on :
            - node2 
    
    networks:
      mongocluster:
        driver: bridge 
    

    volume部分具有与根不同的绝对路径实际上,docker文件会在root上创建一个自我配置文件,因此,如果您将root作为docker-compose的安装位置,请将其更改为别的位置,现在配置文件设置将永远不会在docker-install up / down上删除。

    The volume section has absolute path which is different from the root.Actually docker file creates a self config file on root , so if u have root as a docker-compose install location change it to else where, and now the config file settings would never delete on docker-install up/down.

    这篇关于如何使用新的守护进程标志重启现有的MongoDB Docker容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆