1. 环境准备
- 已安装:CentOS-7.6
- 已备份:Vagrant-CentOS-7.6-x86_64.VirtualBox-docker.box
2. 步骤
- 导入备份镜像(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
2. 编写VagrantFile。
```bash
cd /cygdrive/e/vagrant/mybox/
mkdir -p docker-standalone
cd docker-standalone
# 创建共享目录,并将其设置为windows共享目录(推荐添加everyone读写权限)
mkdir share
echo 'vagrant' > share/README.md
vi VagrantFile
内容如下:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.require_version ">= 1.6.0"
boxes = [
{
:name => "docker-standalone",
:eth1 => "192.168.56.101",
:mem => "6144",
:cpu => "2"
}
]
Vagrant.configure(2) do |config|
config.vm.box = "centos7.6-docker"
# 第一次安装时请注释以下三行配置,配置ssh密码验证(sshd_config)后再打开
config.ssh.username = 'vagrant'
config.ssh.password = 'vagrant'
config.ssh.insert_key = true
# ssh config end
config.vm.box_check_update = false
if Vagrant.has_plugin?("vagrant-vbguest")
config.vbguest.auto_update = false
end
# 禁用系统默认的共享目录
config.vm.synced_folder '.', '/vagrant', disabled: true
boxes.each do |opts|
config.vm.define opts[:name] do |config|
config.vm.hostname = opts[:name]
config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--name", opts[:name]]
v.customize ["modifyvm", :id, "--memory", opts[:mem]]
v.customize ["modifyvm", :id, "--cpus", opts[:cpu]]
end
config.vm.network :private_network, ip: opts[:eth1]
end
end
config.vm.synced_folder "./share", "/mnt/app-data", type: "nfs"
config.bindfs.bind_folder "/mnt/app-data","/share",force_user:"vagrant",force_group:"vagrant",o:"nonempty"
end
独立安装启动
vagrant up docker-standalone ```