scottslowe-learning-tools/vagrant-docker-json/Vagrantfile
Scott Lowe 1da4bc2d7f Add files for Vagrant + Docker + JSON
Add files for a multi-container environment using the Vagrant Docker provider and an external JSON data file. That includes a Vagrantfile, external JSON data file, host VM Vagrantfile, and README.md.
2016-02-10 20:40:18 -07:00

50 lines
1.8 KiB
Ruby

# -*- mode: ruby -*-
# vi: set ft=ruby :
# Specify Vagrant version, Vagrant API version, and Vagrant clone location
Vagrant.require_version ">= 1.6.0"
VAGRANTFILE_API_VERSION = "2"
ENV['VAGRANT_VMWARE_CLONE_DIRECTORY'] = '~/.vagrant'
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'docker'
# Require 'json' module
require 'json'
# Read details of containers to be created from YAML file
# Be sure to edit 'containers.yml' to provide container details
containers = JSON.parse(File.read(File.join(File.dirname(__FILE__), 'containers.json')))
# Create and configure the Docker container(s)
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Perform one-time configuration of Docker provider to specify
# location of Vagrantfile for host VM; comment out this section
# to use default boot2docker box
config.vm.provider "docker" do |docker|
docker.vagrant_vagrantfile = "host/Vagrantfile"
end # config.vm.provider
# Iterate through the entries in the YAML file
containers.each do |container|
config.vm.define container["name"] do |cntnr|
# Disable synced folders for the Docker container
# (prevents an NFS error on "vagrant up")
cntnr.vm.synced_folder ".", "/vagrant", disabled: true
# Configure the Docker provider for Vagrant
cntnr.vm.provider "docker" do |docker|
# Specify the Docker image to use, pull value from YAML file
docker.image = container["image"]
# Specify port mappings, pull value from YAML file
# If omitted, no ports are mapped!
docker.ports = container["ports"]
# Specify a friendly name for the Docker container, pull from YAML file
docker.name = container["name"]
end # contnr.vm.provider
end # config.vm.define
end # containers.each
end # Vagrant.configure