Skip to content

Instantly share code, notes, and snippets.

@SlyDen
Created December 12, 2014 09:51
Show Gist options
  • Save SlyDen/e50dfe55ce7731460155 to your computer and use it in GitHub Desktop.
Save SlyDen/e50dfe55ce7731460155 to your computer and use it in GitHub Desktop.
vagrant file example for boot2docker env https://atlas.hashicorp.com/parallels/boxes/boot2docker
VAGRANTFILE_API_VERSION = "2"
Vagrant.require_version ">= 1.6.3"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define "boot2docker"
config.vm.box = "parallels/boot2docker"
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.synced_folder ".", "/vagrant", type: "nfs"
# Fix busybox/udhcpc issue
config.vm.provision :shell do |s|
s.inline = <<-EOT
if ! grep -qs ^nameserver /etc/resolv.conf; then
sudo /sbin/udhcpc
fi
cat /etc/resolv.conf
EOT
end
# Adjust datetime after suspend and resume
config.vm.provision :shell do |s|
s.inline = <<-EOT
sudo /usr/local/bin/ntpclient -s -h pool.ntp.org
date
EOT
end
config.vm.provision :docker do |d|
d.pull_images "yungsang/busybox"
d.run "simple-echo",
image: "yungsang/busybox",
args: "-p 8080:8080",
cmd: "nc -p 8080 -l -l -e echo hello world!"
end
end
$ vagrant plugin install vagrant-parallels
$ vagrant init parallels/boot2docker
$ vagrant up --provider parallels
$ export DOCKER_HOST_IP=$(vagrant ssh-config | sed -n "s/[ ]*HostName[ ]*//gp")
$ export DOCKER_HOST="tcp://${DOCKER_HOST_IP}:2375"
$ docker version
$ docker images
$ docker ps
$ nc ${DOCKER_HOST_IP} 8080
hello world!
$ docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f3f38ced897a yungsang/busybox:latest nc -p 8080 -l -l -e 27 minutes ago Up 9 minutes 0.0.0.0:8080->8080/tcp simple-echo
$ docker exec $(docker ps -l -q) ps
PID USER COMMAND
1 root nc -p 8080 -l -l -e echo hello world!
21 root ps
$ docker exec -it $(docker ps -l -q) sh
/ # ps
PID USER COMMAND
1 root nc -p 8080 -l -l -e echo hello world!
46 root sh
55 root ps
/ # exit
$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment