From d9ef35ee2c835022cde5ab10b7cd7dfd1c4fbbc2 Mon Sep 17 00:00:00 2001 From: Abiola Ibrahim Date: Fri, 6 Feb 2026 11:55:44 +0100 Subject: [PATCH] nerdctl: propagate CONTAINERD_* and NERDCTL_* environment variables. (#1491) Signed-off-by: Abiola Ibrahim --- cmd/nerdctl.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/cmd/nerdctl.go b/cmd/nerdctl.go index e3afe61..f502d23 100644 --- a/cmd/nerdctl.go +++ b/cmd/nerdctl.go @@ -45,7 +45,24 @@ It is recommended to specify '--' to differentiate from Colima flags. return fmt.Errorf("nerdctl only supports %s runtime", containerd.Name) } - nerdctlArgs := append([]string{"sudo", "nerdctl"}, args...) + // collect CONTAINERD_* and NERDCTL_* environment variables from the host + var envVars []string + for _, env := range os.Environ() { + if strings.HasPrefix(env, "CONTAINERD_") || strings.HasPrefix(env, "NERDCTL_") { + envVars = append(envVars, env) + } + } + + var nerdctlArgs []string + if len(envVars) > 0 { + // use 'sudo env VAR=value ... nerdctl' to pass environment variables + nerdctlArgs = append([]string{"sudo", "env"}, envVars...) + nerdctlArgs = append(nerdctlArgs, "nerdctl") + } else { + nerdctlArgs = []string{"sudo", "nerdctl"} + } + nerdctlArgs = append(nerdctlArgs, args...) + return app.SSH(nerdctlArgs...) }, }