29 days ago

新版本的 vagrant 配置有點不同,所以想用舊的配置檔跑 VM 裡面的 Docker 會失敗

新的要加上
force_host_vm = true

為什麼要加就是自己看一下說明吧,反正就改了
https://www.vagrantup.com/docs/docker/configuration.html#force_host_vm

新的 mysql + rabbitmq + mongo 的範例

Vagrantfile.proxy
VAGRANTFILE_API_VERSION = "2"
 
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|  
  config.vm.box = "ubuntu/trusty64"
  config.vm.provision "docker"
  config.vm.provision "shell", inline:
    "ps aux | grep 'sshd:' | awk '{print $2}' | xargs kill"
  
  config.vm.provider :virtualbox do |vb|
    vb.gui = $vm_gui
    vb.memory = $vm_memory
    vb.cpus = $vm_cpus
  end
  
  config.vm.synced_folder ".", "/vagrant", disabled: true
  
  # Http
  # config.vm.network :forwarded_port, guest: 5566, host: 5566

  # PostgreSQL
  # config.vm.network :forwarded_port, guest: 5432, host: 5432
  
  # MySQL
  config.vm.network :forwarded_port, guest: 3306, host: 3306
  
  # RabbitMQ
  config.vm.network :forwarded_port, guest: 5672, host: 5672
  config.vm.network :forwarded_port, guest: 15672, host: 15672
  
  # MongoDB
  config.vm.network :forwarded_port, guest: 27017, host: 27017
  
  # for i in 64000..65535
  #   config.vm.network :forwarded_port, guest: i, host: i
  # end
end
Vagrantfile
VAGRANTFILE_API_VERSION = "2"
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'docker'

$vm_gui = false
$vm_memory = 2048
$vm_cpus = 2

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  
  config.vm.define "mysql" do |v|
    v.vm.synced_folder ".", "/vagrant", disabled: true
    v.vm.provider "docker" do |d|
      d.force_host_vm = true
      d.name = "mysql"
      d.image = "mysql"
      d.ports = ["3306:3306"]
      d.env = {
        MYSQL_ROOT_PASSWORD: "abcd1234"
      }
      d.vagrant_vagrantfile = "./Vagrantfile.proxy"
    end
  end
  
  config.vm.define "rabbitmq" do |v|
    v.vm.synced_folder ".", "/vagrant", disabled: true
    v.vm.provider "docker" do |d|
      d.force_host_vm = true
      d.name = "rabbitmq"
      d.image = "rabbitmq:management"
      d.ports = ["5672:5672","15672:15672"]
      d.vagrant_vagrantfile = "./Vagrantfile.proxy"
    end
  end
  
  config.vm.define "mongo" do |v|
    v.vm.synced_folder ".", "/vagrant", disabled: true
    v.vm.provider "docker" do |d|
      d.force_host_vm = true
      d.name = "mongo"
      d.image = "mongo"
      d.ports = ["27017:27017"]
      d.vagrant_vagrantfile = "./Vagrantfile.proxy"
    end
  end
end

一樣 vagrant up 就都啟動了

← Define entity resource link in spring data rest vagrant add extra disk →
 
comments powered by Disqus