mirror of
https://github.com/moby/moby.git
synced 2026-08-03 22:51:03 +00:00
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:
@@ -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))
|
||||
}
|
||||
Reference in New Issue
Block a user