Merge pull request #45920 from thaJeztah/fix_expose_npe
daemon/containerd: fix assignment to entry in nil map during commit
This commit is contained in:
commit
e477a57cc5
2 changed files with 27 additions and 2 deletions
|
@ -393,8 +393,11 @@ func containerConfigToOciImageConfig(cfg *container.Config) ocispec.ImageConfig
|
|||
StopSignal: cfg.StopSignal,
|
||||
ArgsEscaped: cfg.ArgsEscaped,
|
||||
}
|
||||
for k, v := range cfg.ExposedPorts {
|
||||
ociCfg.ExposedPorts[string(k)] = v
|
||||
if len(cfg.ExposedPorts) > 0 {
|
||||
ociCfg.ExposedPorts = map[string]struct{}{}
|
||||
for k, v := range cfg.ExposedPorts {
|
||||
ociCfg.ExposedPorts[string(k)] = v
|
||||
}
|
||||
}
|
||||
|
||||
return ociCfg
|
||||
|
|
22
daemon/containerd/image_import_test.go
Normal file
22
daemon/containerd/image_import_test.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
package containerd
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/go-connections/nat"
|
||||
"gotest.tools/v3/assert"
|
||||
is "gotest.tools/v3/assert/cmp"
|
||||
)
|
||||
|
||||
// regression test for https://github.com/moby/moby/issues/45904
|
||||
func TestContainerConfigToOciImageConfig(t *testing.T) {
|
||||
ociCFG := containerConfigToOciImageConfig(&container.Config{
|
||||
ExposedPorts: nat.PortSet{
|
||||
"80/tcp": struct{}{},
|
||||
},
|
||||
})
|
||||
|
||||
expected := map[string]struct{}{"80/tcp": {}}
|
||||
assert.Check(t, is.DeepEqual(ociCFG.ExposedPorts, expected))
|
||||
}
|
Loading…
Add table
Reference in a new issue