github.com/mwhudson/juju@v0.0.0-20160512215208-90ff01f3497f/container/utils.go (about)

     1  package container
     2  
     3  import (
     4  	"os/exec"
     5  	"runtime"
     6  )
     7  
     8  var RunningInContainer = func() bool {
     9  	if runtime.GOOS != "linux" {
    10  		return false
    11  	}
    12  
    13  	/* running-in-container is in init-scripts-helpers, and is smart enough
    14  	 * to ask both systemd and upstart whether or not they know if the task
    15  	 * is running in a container.
    16  	 */
    17  	cmd := exec.Command("running-in-container")
    18  	return cmd.Run() == nil
    19  }
    20  
    21  func ContainersSupported() bool {
    22  	return !RunningInContainer()
    23  }