流浪汉:使用提供者和提供来收集

时间:2017-07-01 10:29:38

标签: docker vagrant vagrant-provision

这是我的主要Vagrant文​​件

Vagrant.configure(2) do |config|
  config.vm.define "app7" do |app7|
    app7.vm.synced_folder "/home/behrad/dunro","/var/www/html"
    app7.vm.network "forwarded_port", id: "ssh", guest: 22, host: 2222, auto_correct: true
    app7.vm.provider "docker" do |docker|
      docker.vagrant_vagrantfile = "dev/app7/Vagrantfile"
      docker.build_dir = "./dev/app7"
      docker.build_args = "-t","dunro/app7:20170701"
      docker.name = "app7"
      docker.ports = ['80:80']
      docker.has_ssh = true
    end
  end
end

和dev / app7 / Vagrantfile

Vagrant.configure(2) do |config|
  config.vm.hostname = "app7"
  config.vm.provision "file", source: "keys/id_rsa.pub", destination: "/var/www/.ssh/authorized_keys"
  config.ssh.username = "www-data"                                 
  config.ssh.private_key_path = "keys/id_rsa"  
end

dev / app7 / Vagrantfile无法正常工作

1 个答案:

答案 0 :(得分:0)

  

dev / app7 / Vagrantfile无法正常工作

是的,它不起作用,因为它不是有效的Vagrantfile。

你基本上已经指示vagrant使用host VM所以从主Vagrantfile,你'告诉vagrant查看另一个Vagrantfile以了解主机VM(将运行docker的主机VM)的配置,所以至少您需要有config.vm.box设置作为此VM的基本框

主机VM Vagrantfile的示例将是

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config|
  config.vm.box = "ubuntu/trusty64"

  config.vm.hostname = "app7"

  config.vm.provision "shell", inline: "echo Hello, World"

  # make sure to have docker installed on this VM
  config.vm.provision "docker"

  config.vm.network :forwarded_port, guest: 80, host: 4567
end

这将创建一个基于ubuntu trusty64的VM(我确保安装最新版本的docker,这样主要的Vagrantfile和docker provider就能正常运行)

在这种情况下,我可以看到我的内联shell配置正在运行,docker配置将安装docker,然后docker主提供程序将在此VM上提取映像