From 840ecaa654bd725fafc9e78c38cb5663ab98c8ea Mon Sep 17 00:00:00 2001 From: Roman Dodin Date: Tue, 1 Dec 2020 09:00:07 +0100 Subject: [PATCH] Fix port binds (#184) * renamed variable to match its data type * fixed missing exposed ports configuration --- clab/config.go | 14 ++++++++------ clab/docker.go | 1 + 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/clab/config.go b/clab/config.go index 89b57f820..35c554599 100644 --- a/clab/config.go +++ b/clab/config.go @@ -99,6 +99,7 @@ type Node struct { Env []string Binds []string // Bind mounts strings (src:dest:options) PortBindings nat.PortMap // PortBindings define the bindings between the container ports and host ports + PortSet nat.PortSet // PortSet define the ports that should be exposed on a container TLSCert string TLSKey string @@ -190,15 +191,15 @@ func (c *cLab) bindsInit(nodeCfg *NodeConfig) []string { } // portsInit produces the nat.PortMap out of the slice of string representation of port bindings -func (c *cLab) portsInit(nodeCfg *NodeConfig) (nat.PortMap, error) { +func (c *cLab) portsInit(nodeCfg *NodeConfig) (nat.PortSet, nat.PortMap, error) { if len(nodeCfg.Ports) != 0 { - _, pm, err := nat.ParsePortSpecs(nodeCfg.Ports) + ps, pb, err := nat.ParsePortSpecs(nodeCfg.Ports) if err != nil { - return nil, err + return nil, nil, err } - return pm, nil + return ps, pb, nil } - return nil, nil + return nil, nil, nil } func (c *cLab) groupInitialization(nodeCfg *NodeConfig, kind string) string { @@ -302,11 +303,12 @@ func (c *cLab) NewNode(nodeName string, nodeCfg NodeConfig, idx int) error { node.Kind = strings.ToLower(c.kindInitialization(&nodeCfg)) node.Binds = c.bindsInit(&nodeCfg) - pb, err := c.portsInit(&nodeCfg) + ps, pb, err := c.portsInit(&nodeCfg) if err != nil { return err } node.PortBindings = pb + node.PortSet = ps switch node.Kind { case "ceos": diff --git a/clab/docker.go b/clab/docker.go index f66dc50e4..94ec05509 100644 --- a/clab/docker.go +++ b/clab/docker.go @@ -178,6 +178,7 @@ func (c *cLab) CreateContainer(ctx context.Context, node *Node) (err error) { Tty: true, User: node.User, Labels: labels, + ExposedPorts: node.PortSet, }, &container.HostConfig{ Binds: node.Binds, PortBindings: node.PortBindings,