Docker Env Made Easy with Vagrant

Intel NUC是款迷你PC, 配备了120G固态硬盘/16G内存, 安装了Debian 8.5操作系统, 运行VirtualBox及Vagrant软件, 连接OpenWrt科学上网, 作为虚拟化平台使用.

运行Ubuntu导致NUC变砖, 返厂维修后, 拿到翻新机. :(

  • OpenWrt: 路由器 (ShadowSocks)
  • MacOSX: 客户端 (Docker Machine + Compose)
  • NUC: 服务器 (VirtualBox + Vagrant + AutoSSH)
  • Debian: 虚拟机 (Docker)

MacOSX (~/.ssh/config)

Host nuc  
    HostName 192.168.31.206
    User kev

Host debian  
    HostName 192.168.31.138
    User vagrant

NUC

# ssh nuc
$ mkdir -p ~/vagrant/{centos,debian,freebsd}
$ cd ~/vagrant/debian
$ vagrant init debian/jessie64
$ vi Vagrantfile
$ vagrant up

NUC (Vagrantfile)

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

Vagrant.configure("2") do |config|

  config.vm.box = "debian/jessie64"

  config.vm.network :public_network, ip: "192.168.31.138"

  config.vm.provider "virtualbox" do |v|
    v.customize ["modifyvm", :id, "--vrde", "on", "--vrdeport", "5000-6000"]
  end

  config.vm.provision :shell, inline: <<-SHELL

    ### install docker
    wget -qO- https://get.docker.com/ | sudo bash
    sudo usermod -aG docker vagrant

    ### install compose
    cd /usr/local/bin
    wget -qO docker-compose https://github.com/docker/compose/releases/download/1.8.0/docker-compose-Linux-x86_64
    chmod +x docker-compose
    ln -s docker-compose fig

    ### install others
    sudo apt-get install -y curl tmux vim

  SHELL

end  

MacOSX

$ sshpass -p vagrant ssh-copy-id -o StrictHostKeyChecking=no debian
$ brew install docker-{compose,machine}
$ docker-machine create --driver generic \
                        --generic-ip-address 192.168.31.138 \
                        --generic-ssh-user vagrant \
                        --generic-ssh-key ~/.ssh/id_rsa default
$ eval $(docker-machine env)
$ docker info

Debian

# ssh debian
$ tmux new vim

NUC (RDP)

# ssh nuc
$ VBoxManage list vms
"centos_default_1469173958847_85967" {e1fdcd5d-e394-441e-a2f3-0752c3935605}
"debian_default_1469684603379_27087" {ee08cf72-cacf-4cc8-bc70-a3f25923e736}
$ VBoxManage showvminfo debian_default_1469684603379_27087 | grep 'VRDE port'
VRDE port:       5000  
# open -a 'Remote Desktop Connection' # 192.168.31.206:5000

Read More