Skip to content

Instantly share code, notes, and snippets.

@michaelsauter
Last active April 28, 2017 09:30
Show Gist options
  • Save michaelsauter/1483a1449b8b228edd91 to your computer and use it in GitHub Desktop.
Save michaelsauter/1483a1449b8b228edd91 to your computer and use it in GitHub Desktop.

Docker Mac binary:

curl -L -o docker https://get.docker.io/builds/Darwin/x86_64/docker-latest
chmod +x docker
sudo mv docker /usr/local/bin/docker

Install nsenter in the box:

docker run --rm -v /var/lib/boot2docker/:/target jpetazzo/nsenter

Put this next to your Vagrantfile:

#!/bin/sh

vagrant ssh -c "sudo /var/lib/boot2docker/docker-enter $1"

Use it: ./docker-enter container_name

VAGRANTFILE_API_VERSION = "2"
Vagrant.require_version ">= 1.6.3"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define "boot2docker"
config.vm.box = "yungsang/boot2docker"
config.vm.box_check_update = false
config.vm.network "private_network", ip: "192.168.33.10"
# Mount current dir under same path in VM
config.vm.synced_folder ".", Dir.pwd, type: "nfs", mount_options: ["nolock", "vers=3", "udp"]
config.vm.provider :virtualbox do |vb, override|
vb.customize ["modifyvm", :id, "--memory", "2048"]
end
# 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
end
@tonivdv
Copy link

tonivdv commented Feb 13, 2015

Hey @michaelsauter,

Thanks for sharing this gist. However I have a question. Am I mistaken if I say that this setup should work seamlessly as if I would use boot2docker directly ?

Because currently when I run a container from my osx terminal with -v from:to it doesn't share the files to my vagrant box ...

Thanks in advance for your time.

@tonivdv
Copy link

tonivdv commented Feb 16, 2015

I figured it out. Boot2docker by default shares /Users on mac, thus you're able to use the absolute path ... however when using vagrant it all depends on how you share initially ... Following post helped me understanding this http://felipejfc.com/2014/08/29/vagrant_docker_sync_folder/.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment