docker
itamae
vagrant
Docker | Vagrant + Itamae で Docker の Hello world #docker #itamae #vagrant
概要
Vagrant + Itamae で Docker の Hello world まで疎通させます
構成
OS: 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 の編集
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 )を作成
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