Setup container environment variables before user
The user setup code looks at the env to setup HOME.
@@ -758,6 +758,13 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID, contai
specgen.AddAnnotation("org.opencontainers.image.stopSignal", containerImageConfig.Config.StopSignal)
}
+ // Add environment variables from image the CRI configuration
+ envs := mergeEnvs(containerImageConfig, containerConfig.GetEnvs())
+ for _, e := range envs {
+ parts := strings.SplitN(e, "=", 2)
+ specgen.AddProcessEnv(parts[0], parts[1])
+ }
+
// Setup user and groups
if linux != nil {
if err := setupContainerUser(ctx, &specgen, mountPoint, mountLabel, containerInfo.RunDir, linux.GetSecurityContext(), containerImageConfig); err != nil {
@@ -777,12 +784,6 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID, contai
}
specgen.SetProcessArgs(processArgs)
- envs := mergeEnvs(containerImageConfig, containerConfig.GetEnvs())
- for _, e := range envs {
- parts := strings.SplitN(e, "=", 2)
- specgen.AddProcessEnv(parts[0], parts[1])
- }
-
// Set working directory
// Pick it up from image config first and override if specified in CRI
containerCwd := "/"
