From 8c11b537ba0b691b747f8f5089229033432d257f Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Fri, 27 May 2016 17:36:07 -0400 Subject: [PATCH] Allow Mac/Windows users to use Docker native --- plugins/providers/docker/config.rb | 10 +++++++++- test/unit/plugins/providers/docker/config_test.rb | 1 + website/source/docs/docker/configuration.html.md | 6 +++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/plugins/providers/docker/config.rb b/plugins/providers/docker/config.rb index ba042607aed..4f32b48e4fd 100644 --- a/plugins/providers/docker/config.rb +++ b/plugins/providers/docker/config.rb @@ -1,5 +1,7 @@ require "pathname" +require_relative "../../../lib/vagrant/util/platform" + module VagrantPlugins module DockerProvider class Config < Vagrant.plugin("2", :config) @@ -202,7 +204,6 @@ def finalize! @create_args = [] if @create_args == UNSET_VALUE @dockerfile = nil if @dockerfile == UNSET_VALUE @env ||= {} - @force_host_vm = false if @force_host_vm == UNSET_VALUE @has_ssh = false if @has_ssh == UNSET_VALUE @image = nil if @image == UNSET_VALUE @name = nil if @name == UNSET_VALUE @@ -223,6 +224,13 @@ def finalize! @host_vm_build_dir_options = nil end + # On non-linux platforms (where there is no native docker), force the + # host VM. Other users can optionally disable this by setting the + # value explicitly to false in their Vagrantfile. + if @force_host_vm == UNSET_VALUE + @force_host_vm = !Vagrant::Util::Platform.linux? + end + # The machine name must be a symbol @vagrant_machine = @vagrant_machine.to_sym if @vagrant_machine diff --git a/test/unit/plugins/providers/docker/config_test.rb b/test/unit/plugins/providers/docker/config_test.rb index 7579092f957..a938fcf4543 100644 --- a/test/unit/plugins/providers/docker/config_test.rb +++ b/test/unit/plugins/providers/docker/config_test.rb @@ -60,6 +60,7 @@ def valid_defaults before do # By default lets be Linux for validations Vagrant::Util::Platform.stub(linux: true) + Vagrant::Util::Platform.stub(linux?: true) end it "should be invalid if both build dir and image are set" do diff --git a/website/source/docs/docker/configuration.html.md b/website/source/docs/docker/configuration.html.md index fcd8c14f71a..ce463b1c8a8 100644 --- a/website/source/docs/docker/configuration.html.md +++ b/website/source/docs/docker/configuration.html.md @@ -50,7 +50,11 @@ General settings: * `force_host_vm` (boolean) - If true, then a host VM will be spun up even if the computer running Vagrant supports Linux containers. This - is useful to enforce a consistent environment to run Docker. + is useful to enforce a consistent environment to run Docker. This value + defaults to "true" on Mac and Windows hosts and defaults to "false" on + Linux hosts. Mac/Windows users who choose to use a different Docker + provider or opt-in to the native Docker builds can explicitly set this + value to false to disable the behavior. * `has_ssh` (boolean) - If true, then Vagrant will support SSH with the container. This allows `vagrant ssh` to work, provisioners, etc.