Created
April 18, 2016 11:16
-
-
Save p120ph37/0e2dc718c9ea3400da0590792eac208f to your computer and use it in GitHub Desktop.
Use Vagrant's "docker-provider" to run a Dockerfile on any host. Works around issues with the current hashicorp/boot2docker image.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vagrant.configure(2) do |config| | |
# Generate shared docker-host Vagrantfile | |
# (the default hashicorp/boot2docker image doesn't work very well at the moment) | |
env = Vagrant::Environment.new | |
vf_path = env.data_dir.join("docker-virtualbox-host", "Vagrantfile") | |
begin | |
env.lock("docker-provider-virtualbox-hostvm") do | |
vf_path.dirname.mkpath | |
File.open(vf_path, 'w') do |file| | |
file.write <<-EOF | |
Vagrant.configure(2) do |config| | |
config.vm.box = "dduportal/boot2docker" | |
# make sure Docker starts before SSH | |
config.vm.provision "shell", inline: <<-SCRIPT | |
# make sure Docker starts before SSH | |
sed -i \ | |
-e '/Launch Docker/,$!{/Configure SSHD/,/^$/{H;d;};}' \ | |
-e '/Launch Docker/,/^$/{/^$/g;}' \ | |
/opt/bootscript.sh | |
# and make sure it is started now | |
/etc/rc.d/docker | |
SCRIPT | |
end | |
EOF | |
end | |
end | |
rescue Vagrant::Errors::EnvironmentLockedError | |
# Lock contention, just retry | |
retry | |
end | |
# Spawn a Docker container, natively if possible, or with the help of a VM. | |
config.vm.define :default do |box_config| | |
box_config.vm.provider :docker do |d| | |
d.build_dir = "." | |
d.vagrant_vagrantfile = vf_path | |
d.remains_running = false | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There are three issues this works around: