Docker | 使用 Vagrant 和 Itamae 来实现 Docker 的 Hello world #docker #itamae #vagrant
Docker: 容器
Itamae: 廚師
Vagrant: 游牧民
使用Docker | Vagrant + Itamae创建Docker的Hello world #docker #itamae #vagrant
总结
用Vagrant和Itamae来使Docker达到Hello World的通信。
构成
操作系统:Ubuntu 1404(Vagrant Box:’box-cutter/ubuntu1404’)
Vagrant版本:1.6.5
Itamae版本:v1.0.8
做法
建立工作目录
$ mkdir docker_sample
$ cd docker_sample
生成一个 Vagrantfile 的模板
$ Vagrant init -m
$ ls -F | grep Vagrantfile
Vagrantfile
编辑Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define "dockersample" do |web|
web.vm.provider :virtualbox do |vb|
vb.name = "dockersample"
end
web.vm.hostname = "dockersample"
web.vm.box = "box-cutter/ubuntu1404"
end
end
创建 Itamae 的配方(docker.rb)。
execute "apt-get update" do
command "sudo apt-get update"
end
package 'docker.io' do
action :install
end
execute "enable tab-completion of Docker commands in BASH" do
command <<-COMMANDS
#!/bin/bash
source /etc/bash_completion.d/docker.io
end
end
execute "install apt-transport-https" do
command <<-COMMANDS
[ -e /usr/lib/apt/methods/https ] || {
apt-get update
apt-get install apt-transport-https
}
COMMANDS
end
execute "install apt-transport-https" do
command <<-COMMANDS
sudo sh -c "wget -qO- https://get.docker.io/gpg | apt-key add -"
sudo sh -c "echo deb http://get.docker.io/ubuntu docker main\ > /etc/apt/sources.list.d/docker.list"
sudo apt-get update
COMMANDS
end
package 'lxc-docker' do
action :install
options("-y")
end
使用 Vagrant up 命令来创建虚拟环境。
$ vagrant up
$ vagrant ssh
Welcome to Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-32-generic x86_64)
* Documentation: https://help.ubuntu.com/
Last login: Sun Nov 2 22:18:17 2014 from 10.0.2.2
执行Itamae的食谱
$ vagrant ssh-config --host dockersample
$ itamae ssh --vagrant -h dockersample docker.rb
确认Docker的安装。
$ vagrant ssh
# 初回実行のため ubuntu:14.04 のイメージの取得を行う
vagrant@dockersample:~$ sudo docker run ubuntu:14.04 /bin/echo 'Hello world'
Unable to find image 'ubuntu:14.04' locally
ubuntu:14.04: The image you are pulling has been verified
511136ea3c5a: Pull complete
d497ad3926c8: Pull complete
ccb62158e970: Pull complete
e791be0477f2: Pull complete
3680052c0f5c: Pull complete
22093c35d77b: Pull complete
5506de2b643b: Pull complete
Status: Downloaded newer image for ubuntu:14.04
Hello world
# 2回目実行のため ubuntu:14.04 のイメージは取得済み
vagrant@dockersample:~$ sudo docker run ubuntu:14.04 /bin/echo 'Hello world'
Hello world