Skip to content

Commit

Permalink
Merge pull request jesseduffield#511 from rajiv-k/docker-host-ssh
Browse files Browse the repository at this point in the history
fix: Properly support remote docker daemon over ssh
  • Loading branch information
jesseduffield authored May 30, 2024
2 parents 89020d6 + 42b7ba1 commit 06ab7b7
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions pkg/commands/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import (
)

const (
APIVersion = "1.25"
APIVersion = "1.25"
dockerHostEnvKey = "DOCKER_HOST"
)

// DockerCommand is our main docker interface
Expand Down Expand Up @@ -72,14 +73,28 @@ func (c *DockerCommand) NewCommandObject(obj CommandObject) CommandObject {

// NewDockerCommand it runs docker commands
func NewDockerCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.TranslationSet, config *config.AppConfig, errorChan chan error) (*DockerCommand, error) {
dockerHost, err := determineDockerHost()
if err != nil {
ogLog.Printf("> could not determine host %v", err)
}

// NOTE: Inject the determined docker host to the environment. This allows the
// `SSHHandler.HandleSSHDockerHost()` to create a local unix socket tunneled
// over SSH to the specified ssh host.
if strings.HasPrefix(dockerHost, "ssh://") {
os.Setenv(dockerHostEnvKey, dockerHost)
}

tunnelCloser, err := ssh.NewSSHHandler(osCommand).HandleSSHDockerHost()
if err != nil {
ogLog.Fatal(err)
}

dockerHost, err := determineDockerHost()
if err != nil {
ogLog.Printf("> could not determine host %v", err)
// Retrieve the docker host from the environment which could have been set by
// the `SSHHandler.HandleSSHDockerHost()` and override `dockerHost`.
dockerHostFromEnv := os.Getenv(dockerHostEnvKey)
if dockerHostFromEnv != "" {
dockerHost = dockerHostFromEnv
}

cli, err := client.NewClientWithOpts(client.FromEnv, client.WithVersion(APIVersion), client.WithHost(dockerHost))
Expand Down

0 comments on commit 06ab7b7

Please sign in to comment.