1. 环境准备

  • 已安装:CentOS-7.6
  • 已备份:Vagrant-CentOS-7.6-x86_64.VirtualBox-docker.box

    2. 步骤

  1. 导入备份镜像(box)。 ```powershell cd /cygdrive/i/learn_resource/tools/vagrant/box/CentOS vagrant box add centos7.6-docker Vagrant-CentOS-7.6-x86_64.VirtualBox-docker.box

查看box列表

vagrant box list

  1. 2. 编写VagrantFile
  2. ```bash
  3. cd /cygdrive/e/vagrant/mybox/
  4. mkdir -p docker-standalone
  5. cd docker-standalone
  6. # 创建共享目录,并将其设置为windows共享目录(推荐添加everyone读写权限)
  7. mkdir share
  8. echo 'vagrant' > share/README.md
  9. vi VagrantFile
  1. 内容如下:
  1. # -*- mode: ruby -*-
  2. # vi: set ft=ruby :
  3. Vagrant.require_version ">= 1.6.0"
  4. boxes = [
  5. {
  6. :name => "docker-standalone",
  7. :eth1 => "192.168.56.101",
  8. :mem => "6144",
  9. :cpu => "2"
  10. }
  11. ]
  12. Vagrant.configure(2) do |config|
  13. config.vm.box = "centos7.6-docker"
  14. # 第一次安装时请注释以下三行配置,配置ssh密码验证(sshd_config)后再打开
  15. config.ssh.username = 'vagrant'
  16. config.ssh.password = 'vagrant'
  17. config.ssh.insert_key = true
  18. # ssh config end
  19. config.vm.box_check_update = false
  20. if Vagrant.has_plugin?("vagrant-vbguest")
  21. config.vbguest.auto_update = false
  22. end
  23. # 禁用系统默认的共享目录
  24. config.vm.synced_folder '.', '/vagrant', disabled: true
  25. boxes.each do |opts|
  26. config.vm.define opts[:name] do |config|
  27. config.vm.hostname = opts[:name]
  28. config.vm.provider "virtualbox" do |v|
  29. v.customize ["modifyvm", :id, "--name", opts[:name]]
  30. v.customize ["modifyvm", :id, "--memory", opts[:mem]]
  31. v.customize ["modifyvm", :id, "--cpus", opts[:cpu]]
  32. end
  33. config.vm.network :private_network, ip: opts[:eth1]
  34. end
  35. end
  36. config.vm.synced_folder "./share", "/mnt/app-data", type: "nfs"
  37. config.bindfs.bind_folder "/mnt/app-data","/share",force_user:"vagrant",force_group:"vagrant",o:"nonempty"
  38. end
  1. 初始化虚拟机。 ```bash

    整体启动

    cd /cygdrive/e/vagrant/mybox/docker-standalone vagrant up

独立安装启动

vagrant up docker-standalone ```