Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cli/command/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ func getServerHost(hosts []string, tlsOptions *tlsconfig.Options) (string, error
var host string
switch len(hosts) {
case 0:
host = os.Getenv("DOCKER_HOST")
host = os.Getenv(client.EnvOverrideHost)
case 1:
host = hosts[0]
default:
Expand All @@ -429,7 +429,7 @@ func UserAgent() string {
// resolveContextName resolves the current context name with the following rules:
// - setting both --context and --host flags is ambiguous
// - if --context is set, use this value
// - if --host flag or DOCKER_HOST is set, fallbacks to use the same logic as before context-store was added
// - if --host flag or DOCKER_HOST (client.EnvOverrideHost) is set, fallbacks to use the same logic as before context-store was added
// for backward compatibility with existing scripts
// - if DOCKER_CONTEXT is set, use this value
// - if Config file has a globally set "CurrentContext", use this value
Expand All @@ -444,7 +444,7 @@ func resolveContextName(opts *cliflags.CommonOptions, config *configfile.ConfigF
if len(opts.Hosts) > 0 {
return DefaultContextName, nil
}
if _, present := os.LookupEnv("DOCKER_HOST"); present {
if _, present := os.LookupEnv(client.EnvOverrideHost); present {
return DefaultContextName, nil
}
if ctxName, ok := os.LookupEnv("DOCKER_CONTEXT"); ok {
Expand Down
7 changes: 4 additions & 3 deletions cli/command/context/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/docker/cli/cli/command/formatter"
"github.com/docker/cli/cli/context/docker"
flagsHelper "github.com/docker/cli/cli/flags"
"github.com/docker/docker/client"
"github.com/fvbommel/sortorder"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -73,9 +74,9 @@ func runList(dockerCli command.Cli, opts *listOptions) error {
if err := format(dockerCli, opts, contexts); err != nil {
return err
}
if os.Getenv("DOCKER_HOST") != "" {
fmt.Fprint(dockerCli.Err(), "Warning: DOCKER_HOST environment variable overrides the active context. "+
"To use a context, either set the global --context flag, or unset DOCKER_HOST environment variable.\n")
if os.Getenv(client.EnvOverrideHost) != "" {
fmt.Fprintf(dockerCli.Err(), "Warning: %[1]s environment variable overrides the active context. "+
"To use a context, either set the global --context flag, or unset %[1]s environment variable.\n", client.EnvOverrideHost)
}
return nil
}
Expand Down
7 changes: 4 additions & 3 deletions cli/command/context/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/context/store"
"github.com/docker/docker/client"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -41,9 +42,9 @@ func RunUse(dockerCli command.Cli, name string) error {
}
fmt.Fprintln(dockerCli.Out(), name)
fmt.Fprintf(dockerCli.Err(), "Current context is now %q\n", name)
if os.Getenv("DOCKER_HOST") != "" {
fmt.Fprintf(dockerCli.Err(), "Warning: DOCKER_HOST environment variable overrides the active context. "+
"To use %q, either set the global --context flag, or unset DOCKER_HOST environment variable.\n", name)
if os.Getenv(client.EnvOverrideHost) != "" {
fmt.Fprintf(dockerCli.Err(), "Warning: %[1]s environment variable overrides the active context. "+
"To use %[2]q, either set the global --context flag, or unset %[1]s environment variable.\n", client.EnvOverrideHost, name)
}
return nil
}
8 changes: 1 addition & 7 deletions cli/context/docker/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/pem"
"net"
"net/http"
"os"
"time"

"github.com/docker/cli/cli/connhelper"
Expand Down Expand Up @@ -122,12 +121,7 @@ func (c *Endpoint) ClientOpts() ([]client.Opt, error) {
}
}

version := os.Getenv("DOCKER_API_VERSION")
if version != "" {
result = append(result, client.WithVersion(version))
} else {
result = append(result, client.WithAPIVersionNegotiation())
}
result = append(result, client.WithVersionFromEnv(), client.WithAPIVersionNegotiation())
return result, nil
}

Expand Down
10 changes: 6 additions & 4 deletions cli/flags/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/docker/cli/cli/config"
"github.com/docker/cli/opts"
"github.com/docker/docker/client"
"github.com/docker/go-connections/tlsconfig"
"github.com/sirupsen/logrus"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -36,9 +37,10 @@ Refer to https://docs.docker.com/go/formatting/ for more information about forma
)

var (
dockerCertPath = os.Getenv("DOCKER_CERT_PATH")
dockerTLSVerify = os.Getenv("DOCKER_TLS_VERIFY") != ""
dockerTLS = os.Getenv("DOCKER_TLS") != ""
dockerCertPath = os.Getenv(client.EnvOverrideCertPath)
dockerTLSVerify = os.Getenv(client.EnvTLSVerify) != ""
// TODO(thaJeztah) the 'DOCKER_TLS' environment variable is not documented, and does not have a const.
dockerTLS = os.Getenv("DOCKER_TLS") != ""
)

// CommonOptions are options common to both the client and the daemon.
Expand Down Expand Up @@ -84,7 +86,7 @@ func (commonOpts *CommonOptions) InstallFlags(flags *pflag.FlagSet) {
hostOpt := opts.NewNamedListOptsRef("hosts", &commonOpts.Hosts, nil)
flags.VarP(hostOpt, "host", "H", "Daemon socket(s) to connect to")
flags.StringVarP(&commonOpts.Context, "context", "c", "",
`Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with "docker context use")`)
`Name of the context to use to connect to the daemon (overrides `+client.EnvOverrideHost+` env var and default context set with "docker context use")`)
}

// SetDefaultOptions sets default values for options after flag parsing is
Expand Down
7 changes: 4 additions & 3 deletions internal/test/environment/testenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"
"time"

"github.com/docker/docker/client"
"github.com/pkg/errors"
"gotest.tools/v3/icmd"
"gotest.tools/v3/poll"
Expand All @@ -19,15 +20,15 @@ func Setup() error {
if dockerHost == "" {
return errors.New("$TEST_DOCKER_HOST must be set")
}
if err := os.Setenv("DOCKER_HOST", dockerHost); err != nil {
if err := os.Setenv(client.EnvOverrideHost, dockerHost); err != nil {
return err
}

if dockerCertPath := os.Getenv("TEST_DOCKER_CERT_PATH"); dockerCertPath != "" {
if err := os.Setenv("DOCKER_CERT_PATH", dockerCertPath); err != nil {
if err := os.Setenv(client.EnvOverrideCertPath, dockerCertPath); err != nil {
return err
}
if err := os.Setenv("DOCKER_TLS_VERIFY", "1"); err != nil {
if err := os.Setenv(client.EnvTLSVerify, "1"); err != nil {
return err
}
}
Expand Down