@@ -28,7 +28,8 @@ import ( |
|
|
28 |
28 |
) |
29 |
29 |
|
30 |
30 |
const ( |
31 |
|
-APIVersion = "1.25" |
|
31 |
+APIVersion = "1.25" |
|
32 |
+dockerHostEnvKey = "DOCKER_HOST" |
32 |
33 |
) |
33 |
34 |
|
34 |
35 |
// DockerCommand is our main docker interface |
@@ -72,14 +73,28 @@ func (c *DockerCommand) NewCommandObject(obj CommandObject) CommandObject { |
|
|
72 |
73 |
|
73 |
74 |
// NewDockerCommand it runs docker commands |
74 |
75 |
func NewDockerCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.TranslationSet, config *config.AppConfig, errorChan chan error) (*DockerCommand, error) { |
|
76 |
+dockerHost, err := determineDockerHost() |
|
77 |
+if err != nil { |
|
78 |
+ogLog.Printf("> could not determine host %v", err) |
|
79 |
+ } |
|
80 |
+ |
|
81 |
+// NOTE: Inject the determined docker host to the environment. This allows the |
|
82 |
+// `SSHHandler.HandleSSHDockerHost()` to create a local unix socket tunneled |
|
83 |
+// over SSH to the specified ssh host. |
|
84 |
+if strings.HasPrefix(dockerHost, "ssh://") { |
|
85 |
+os.Setenv(dockerHostEnvKey, dockerHost) |
|
86 |
+ } |
|
87 |
+ |
75 |
88 |
tunnelCloser, err := ssh.NewSSHHandler(osCommand).HandleSSHDockerHost() |
76 |
89 |
if err != nil { |
77 |
90 |
ogLog.Fatal(err) |
78 |
91 |
} |
79 |
92 |
|
80 |
|
-dockerHost, err := determineDockerHost() |
81 |
|
-if err != nil { |
82 |
|
-ogLog.Printf("> could not determine host %v", err) |
|
93 |
+// Retrieve the docker host from the environment which could have been set by |
|
94 |
+// the `SSHHandler.HandleSSHDockerHost()` and override `dockerHost`. |
|
95 |
+dockerHostFromEnv := os.Getenv(dockerHostEnvKey) |
|
96 |
+if dockerHostFromEnv != "" { |
|
97 |
+dockerHost = dockerHostFromEnv |
83 |
98 |
} |
84 |
99 |
|
85 |
100 |
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithVersion(APIVersion), client.WithHost(dockerHost)) |