diff --git a/internal/services/docker/client/docker_config.go b/internal/services/docker/client/docker_config.go index 697955a2c..47de024c2 100644 --- a/internal/services/docker/client/docker_config.go +++ b/internal/services/docker/client/docker_config.go @@ -22,7 +22,7 @@ import ( ) func NewDockerClient() *docker.Client { - dockerClient, err := docker.NewClientWithOpts(docker.WithAPIVersionNegotiation()) + dockerClient, err := docker.NewClientWithOpts(docker.FromEnv, docker.WithAPIVersionNegotiation()) if err != nil { logger.LogPanicWithLevel(messages.MsgPanicNotConnectDocker, err) } diff --git a/internal/services/docker/client/docker_config_test.go b/internal/services/docker/client/docker_config_test.go index 4c651b93b..0725d2709 100644 --- a/internal/services/docker/client/docker_config_test.go +++ b/internal/services/docker/client/docker_config_test.go @@ -16,6 +16,7 @@ package client import ( "io" + "os" "strings" "testing" @@ -30,6 +31,15 @@ func TestNewDockerAPI(t *testing.T) { NewDockerClient() }) }) + + t.Run("Should use docker host from environment variable", func(t *testing.T) { + dockerHost := "unix:///path/docker/socket" + os.Setenv("DOCKER_HOST", dockerHost) + + c := NewDockerClient() + + assert.Equal(t, dockerHost, c.DaemonHost()) + }) } func TestMock(t *testing.T) {