summaryrefslogtreecommitdiff
path: root/lib/chef/dsl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chef/dsl')
-rw-r--r--lib/chef/dsl/platform_introspection.rb7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/chef/dsl/platform_introspection.rb b/lib/chef/dsl/platform_introspection.rb
index 4ccdb34981..a0c2d33967 100644
--- a/lib/chef/dsl/platform_introspection.rb
+++ b/lib/chef/dsl/platform_introspection.rb
@@ -254,8 +254,11 @@ class Chef
# === Returns
# true:: if the current node is a docker container
# false:: if the current node is not a docker container
- def docker?(node)
- ::File.exist?("/.dockerinit") || ::File.exist?("/.dockerenv")
+ def docker?(node = run_context.nil? ? nil : run_context.node)
+ # Using "File.exist?('/.dockerinit') || File.exist?('/.dockerenv')" makes Travis sad,
+ # and that makes us sad too.
+ node && node[:virtualization] && node[:virtualization][:systems] &&
+ node[:virtualization][:systems][:docker] && node[:virtualization][:systems][:docker] == "guest"
end
end