Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass environment to docker commands #9616

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
15 changes: 7 additions & 8 deletions pkg/drivers/kic/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,16 +524,15 @@ func PointToHostDockerDaemon() error {
p := os.Getenv(constants.MinikubeActiveDockerdEnv)
if p != "" {
klog.Infof("shell is pointing to dockerd inside minikube. will unset to use host")
}

for i := range constants.DockerDaemonEnvs {
e := constants.DockerDaemonEnvs[i]
err := os.Setenv(e, "")
if err != nil {
return errors.Wrapf(err, "resetting %s env", e)
for i := range constants.DockerDaemonEnvs {
e := constants.DockerDaemonEnvs[i]
err := os.Setenv(e, "")
4c0n marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return errors.Wrapf(err, "resetting %s env", e)
}
}

}

return nil
}

Expand Down
17 changes: 15 additions & 2 deletions pkg/minikube/cruntime/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cruntime

import (
"fmt"
"os"
"os/exec"
"path"
"strings"
Expand Down Expand Up @@ -75,6 +76,7 @@ func (r *Docker) Style() style.Enum {
func (r *Docker) Version() (string, error) {
// Note: the server daemon has to be running, for this call to return successfully
c := exec.Command("docker", "version", "--format", "{{.Server.Version}}")
c.Env = os.Environ()
rr, err := r.Runner.RunCmd(c)
if err != nil {
return "", err
Expand Down Expand Up @@ -137,6 +139,7 @@ func (r *Docker) Disable() error {
func (r *Docker) ImageExists(name string, sha string) bool {
// expected output looks like [SHA_ALGO:SHA]
c := exec.Command("docker", "image", "inspect", "--format", "{{.Id}}", name)
c.Env = os.Environ()
4c0n marked this conversation as resolved.
Show resolved Hide resolved
rr, err := r.Runner.RunCmd(c)
if err != nil {
return false
Expand All @@ -151,6 +154,7 @@ func (r *Docker) ImageExists(name string, sha string) bool {
func (r *Docker) LoadImage(path string) error {
klog.Infof("Loading image: %s", path)
c := exec.Command("docker", "load", "-i", path)
c.Env = os.Environ()
if _, err := r.Runner.RunCmd(c); err != nil {
return errors.Wrap(err, "loadimage docker.")
}
Expand All @@ -161,6 +165,7 @@ func (r *Docker) LoadImage(path string) error {
func (r *Docker) CGroupDriver() (string, error) {
// Note: the server daemon has to be running, for this call to return successfully
c := exec.Command("docker", "info", "--format", "{{.CgroupDriver}}")
c.Env = os.Environ()
rr, err := r.Runner.RunCmd(c)
if err != nil {
return "", err
Expand Down Expand Up @@ -194,7 +199,9 @@ func (r *Docker) ListContainers(o ListOptions) ([]string, error) {
}

args = append(args, fmt.Sprintf("--filter=name=%s", nameFilter), "--format={{.ID}}")
rr, err := r.Runner.RunCmd(exec.Command("docker", args...))
cmd := exec.Command("docker", args...)
cmd.Env = os.Environ()
rr, err := r.Runner.RunCmd(cmd)
if err != nil {
return nil, errors.Wrapf(err, "docker")
}
Expand All @@ -215,6 +222,7 @@ func (r *Docker) KillContainers(ids []string) error {
klog.Infof("Killing containers: %s", ids)
args := append([]string{"rm", "-f"}, ids...)
c := exec.Command("docker", args...)
c.Env = os.Environ()
if _, err := r.Runner.RunCmd(c); err != nil {
return errors.Wrap(err, "Killing containers docker.")
}
Expand All @@ -229,6 +237,7 @@ func (r *Docker) StopContainers(ids []string) error {
klog.Infof("Stopping containers: %s", ids)
args := append([]string{"stop"}, ids...)
c := exec.Command("docker", args...)
c.Env = os.Environ()
if _, err := r.Runner.RunCmd(c); err != nil {
return errors.Wrap(err, "docker")
}
Expand All @@ -243,6 +252,7 @@ func (r *Docker) PauseContainers(ids []string) error {
klog.Infof("Pausing containers: %s", ids)
args := append([]string{"pause"}, ids...)
c := exec.Command("docker", args...)
c.Env = os.Environ()
if _, err := r.Runner.RunCmd(c); err != nil {
return errors.Wrap(err, "docker")
}
Expand All @@ -257,6 +267,7 @@ func (r *Docker) UnpauseContainers(ids []string) error {
klog.Infof("Unpausing containers: %s", ids)
args := append([]string{"unpause"}, ids...)
c := exec.Command("docker", args...)
c.Env = os.Environ()
if _, err := r.Runner.RunCmd(c); err != nil {
return errors.Wrap(err, "docker")
}
Expand Down Expand Up @@ -369,7 +380,9 @@ func (r *Docker) Preload(cfg config.KubernetesConfig) error {

// dockerImagesPreloaded returns true if all images have been preloaded
func dockerImagesPreloaded(runner command.Runner, images []string) bool {
rr, err := runner.RunCmd(exec.Command("docker", "images", "--format", "{{.Repository}}:{{.Tag}}"))
cmd := exec.Command("docker", "images", "--format", "{{.Repository}}:{{.Tag}}")
cmd.Env = os.Environ()
rr, err := runner.RunCmd(cmd)
if err != nil {
return false
}
Expand Down
1 change: 1 addition & 0 deletions pkg/minikube/registry/drvs/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func status() registry.State {
defer cancel()

cmd := exec.CommandContext(ctx, oci.Docker, "version", "--format", "{{.Server.Os}}-{{.Server.Version}}")
cmd.Env = os.Environ()
o, err := cmd.Output()
if err != nil {
if ctx.Err() == context.DeadlineExceeded {
Expand Down