Skip to content

Commit

Permalink
bugfix: fix pouch inspect does not return Ports in NetworkSettings.
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Xu <[email protected]>
  • Loading branch information
xiaoxubeii authored and allencloud committed Nov 5, 2018
1 parent d41ecf0 commit 638b38f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions daemon/mgr/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ func (mgr *ContainerManager) Create(ctx context.Context, name string, config *ty
container.NetworkSettings.Networks = make(map[string]*types.EndpointSettings)
container.NetworkSettings.Networks[config.HostConfig.NetworkMode] = new(types.EndpointSettings)
}
container.NetworkSettings.Ports = config.HostConfig.PortBindings

if err := parseSecurityOpts(container, config.HostConfig.SecurityOpt); err != nil {
return nil, err
Expand Down
16 changes: 16 additions & 0 deletions test/cli_inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,19 @@ func (suite *PouchInspectSuite) TestContainerInspectState(c *check.C) {
output = command.PouchRun("inspect", "-f", "{{.State.Status}}", name).Stdout()
c.Assert(strings.TrimSpace(output), check.Equals, "stopped")
}

func (suite *PouchInspectSuite) TestContainerInspectPorts(c *check.C) {
name := "TestContainerInspectPorts"
command.PouchRun("run", "-d", "--name", name, "-p", "8080:80", busyboxImage, "top").Assert(c, icmd.Success)
defer DelContainerForceMultyTime(c, name)

output := command.PouchRun("inspect", name).Stdout()

containers := make([]types.ContainerJSON, 1)
err := json.Unmarshal([]byte(output), &containers)
if err != nil || len(containers) == 0 {
c.Fatal("fail to format container json")
}
data, _ := json.Marshal(containers[0].NetworkSettings.Ports)
c.Assert(string(data), check.Equals, "{\"80/tcp\":[{\"HostPort\":\"8080\"}]}")
}

0 comments on commit 638b38f

Please sign in to comment.