11package commands
22
33import (
4+ "github.com/docker/cli/cli/context/docker"
45 "fmt"
56 "io/ioutil"
67 "os"
@@ -18,6 +19,8 @@ import (
1819 "github.com/docker/cli/cli/command"
1920 "github.com/docker/cli/cli/context/store"
2021 "github.com/docker/distribution/reference"
22+ "github.com/docker/docker/api/types/container"
23+ "github.com/docker/docker/api/types/mount"
2124 "github.com/pkg/errors"
2225)
2326
@@ -76,13 +79,27 @@ func duffleHome() home.Home {
7679}
7780
7881// prepareDriver prepares a driver per the user's request.
79- func prepareDriver (dockerCli command.Cli ) (driver.Driver , error ) {
82+ func prepareDriver (dockerCli command.Cli , bindLocalSocket bool ) (driver.Driver , error ) {
8083 driverImpl , err := driver .Lookup ("docker" )
8184 if err != nil {
8285 return driverImpl , err
8386 }
8487 if d , ok := driverImpl .(* driver.DockerDriver ); ok {
8588 d .SetDockerCli (dockerCli )
89+ if bindLocalSocket {
90+ d .AddConfigurationOptions (func (config * container.Config , hostConfig * container.HostConfig ) error {
91+ config .User = "0:0"
92+ mounts := []mount.Mount {
93+ {
94+ Type : mount .TypeBind ,
95+ Source : "/var/run/docker.sock" ,
96+ Target : "/var/run/docker.sock" ,
97+ },
98+ }
99+ hostConfig .Mounts = mounts
100+ return nil
101+ })
102+ }
86103 }
87104
88105 // Load any driver-specific config out of the environment.
@@ -161,3 +178,30 @@ func resolveBundle(dockerCli command.Cli, name string, pullRef bool, insecureReg
161178 }
162179 return nil , fmt .Errorf ("could not resolve bundle %q" , name )
163180}
181+
182+ func requiresBindMount (targetContextName string , targetOrchestrator string , dockerCli command.Cli ) (bool , error ){
183+ if targetOrchestrator == "kubernetes" {
184+ return false , nil
185+ }
186+ ctxMeta , err := dockerCli .ContextStore ().GetContextMetadata (targetContextName )
187+ if err != nil {
188+ return false , err
189+ }
190+ dockerCtx , err := command .GetDockerContext (ctxMeta )
191+ if err != nil {
192+ return false , err
193+ }
194+ if dockerCtx .StackOrchestrator == command .OrchestratorKubernetes {
195+ return false , nil
196+ }
197+ dockerEndpoint , err := docker .EndpointFromContext (ctxMeta )
198+ if err != nil {
199+ return false , err
200+ }
201+ host := dockerEndpoint .Host
202+ switch host {
203+ case "" , "unix:///var/run/docker.sock" , "npipe:////./pipe/docker_engine" :
204+ return true , nil
205+ }
206+ return false , nil
207+ }
0 commit comments