Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit efce5ff

Browse files
committed
container: fix the issue of missing Env from container image
Signed-off-by: fupan <[email protected]>
1 parent 1ce4312 commit efce5ff

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

daemon/pod/container.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ func (c *Container) createByEngine() (*dockertypes.ContainerJSON, error) {
504504
if len(c.spec.Envs) != 0 {
505505
envs := []string{}
506506
for _, env := range c.spec.Envs {
507+
507508
envs = append(envs, env.Env+"="+env.Value)
508509
}
509510
config.Env = envs
@@ -529,6 +530,19 @@ func (c *Container) createByEngine() (*dockertypes.ContainerJSON, error) {
529530
return nil, err
530531
}
531532

533+
for _, v := range rsp.Config.Env {
534+
pair := strings.SplitN(v, "=", 2)
535+
var env = apitypes.EnvironmentVar{}
536+
537+
if len(pair) == 2 {
538+
env = apitypes.EnvironmentVar{Env: pair[0], Value: pair[1]}
539+
} else if len(pair) == 1 {
540+
env = apitypes.EnvironmentVar{Env: pair[0], Value: ""}
541+
}
542+
543+
c.spec.Envs = append(c.spec.Envs, &env)
544+
}
545+
532546
c.spec.Id = ccs.ID
533547
c.updateLogPrefix()
534548
return rsp, nil
@@ -567,17 +581,13 @@ func containerMounts(cjson *dockertypes.ContainerJSON) []vc.Mount {
567581
return mnts
568582
}
569583

570-
func (c *Container) ociEnv(cjson *dockertypes.ContainerJSON) []string {
584+
func (c *Container) ociEnv() []string {
571585
var envs []string
572586

573587
for _, env := range c.spec.Envs {
574588
envs = append(envs, env.Env+"="+env.Value)
575589
}
576590

577-
for _, env := range cjson.Config.Env {
578-
envs = append(envs, env)
579-
}
580-
581591
return envs
582592
}
583593

@@ -589,7 +599,7 @@ func (c *Container) ociSpec(cjson *dockertypes.ContainerJSON) *specs.Spec {
589599
ocispec.Root.Readonly = c.spec.ReadOnly
590600

591601
ocispec.Process.Args = c.spec.Command
592-
ocispec.Process.Env = c.ociEnv(cjson)
602+
ocispec.Process.Env = c.ociEnv()
593603
ocispec.Process.Cwd = c.spec.Workdir
594604
ocispec.Process.Terminal = c.spec.Tty
595605
/*

0 commit comments

Comments
 (0)