From 5139b853fa387968af1268d6a1fb4290d9f3c62b Mon Sep 17 00:00:00 2001 From: Hao Date: Fri, 29 Apr 2016 22:12:20 -0400 Subject: [PATCH] privilege enabled docker container (#3475) Issue #2724 --- builder/docker/config.go | 1 + builder/docker/driver.go | 1 + builder/docker/driver_docker.go | 3 +++ builder/docker/step_run.go | 1 + 4 files changed, 6 insertions(+) diff --git a/builder/docker/config.go b/builder/docker/config.go index ad8a5634b..159c3a138 100644 --- a/builder/docker/config.go +++ b/builder/docker/config.go @@ -31,6 +31,7 @@ type Config struct { Pull bool RunCommand []string `mapstructure:"run_command"` Volumes map[string]string + Privileged bool `mapstructure:"privileged"` // This is used to login to dockerhub to pull a private base container. For // pushing to dockerhub, see the docker post-processors diff --git a/builder/docker/driver.go b/builder/docker/driver.go index d88c71022..850bd98dd 100644 --- a/builder/docker/driver.go +++ b/builder/docker/driver.go @@ -64,6 +64,7 @@ type ContainerConfig struct { Image string RunCommand []string Volumes map[string]string + Privileged bool } // This is the template that is used for the RunCommand in the ContainerConfig. diff --git a/builder/docker/driver_docker.go b/builder/docker/driver_docker.go index 0d406b1fa..172574e78 100644 --- a/builder/docker/driver_docker.go +++ b/builder/docker/driver_docker.go @@ -210,6 +210,9 @@ func (d *DockerDriver) StartContainer(config *ContainerConfig) (string, error) { // Args that we're going to pass to Docker args := []string{"run"} + if config.Privileged { + args = append(args, "--privileged") + } for host, guest := range config.Volumes { args = append(args, "-v", fmt.Sprintf("%s:%s", host, guest)) } diff --git a/builder/docker/step_run.go b/builder/docker/step_run.go index 7a46ce0e3..a3df4bda6 100644 --- a/builder/docker/step_run.go +++ b/builder/docker/step_run.go @@ -20,6 +20,7 @@ func (s *StepRun) Run(state multistep.StateBag) multistep.StepAction { Image: config.Image, RunCommand: config.RunCommand, Volumes: make(map[string]string), + Privileged: config.Privileged, } for host, container := range config.Volumes {