有什么方法可以将 mongodb 设置为带有 vagrantfile 的服务器吗?

Is there any way for setting up mongodb as a server with vagrantfile?

目前我的环境如下: - Windows 7 64 位 - 流浪者 - 虚拟盒子 - 节点 - Webdriverio - 柴 - Appium

我想用 vagrant 构建一个数据库服务器(使用 mongodb),我将作为客户端从我的 PC 连接。然后我可以 运行 我的脚本在这个数据库上创建测试数据。 服务器(虚拟机)和客户端(物理机)我将只使用一台PC

这个想法可以实现吗?以及如何实施? 有的话请多多指教

有预装 MongoDb 的 vagrant 图像,例如这个 https://app.vagrantup.com/dansweeting/boxes/ubuntu-trusty64-mongo-node

创建一个 vagrant 文件 例如:

# created by Andrei Lupuleasa, December 2018.
Vagrant.require_version ">= 2.2.2"

# Automatically installs required plugin on Windows
if Vagrant::Util::Platform.windows?
  plugin = 'vagrant-winnfsd'

  system "vagrant plugin install #{plugin}" unless Vagrant.has_plugin?(plugin)
end

Vagrant.configure(2) do |config|
  config.vm.box      = "dansweeting/ubuntu-trusty64-mongo-node" # VM OS version
  config.vm.hostname = "vagrantdev"

  # set IP and ports
  config.vm.network "private_network", ip: "192.168.44.10"

  # Sync the sources folder with the machine
  # For Windows `nfs` is preferred due to poor performance of default settings.
  if Vagrant::Util::Platform.windows?
    config.vm.synced_folder "share", "/var/www/html", type: 'nfs'
  else
    config.vm.synced_folder "share", "/var/www/html", mount_options: ["dmode=777","fmode=777"]
  end

  # Set to true if you want automatic checks
  config.vm.box_check_update = false

  # Copy personal private key with access to repository to machine
  config.vm.provision "file", source: "~/.ssh/id_rsa", destination: "~/.ssh/id_rsa"  
  config.vm.provision "file", source: "~/.ssh/id_rsa.pub", destination: "~/.ssh/id_rsa.pub"

end

从 cmd 转到你有 vagrant 文件的地方,比如 cd D:\vagrant 并执行 vagrant up