From 563e1aff560e312965cbd785bf2a61ef51d90603 Mon Sep 17 00:00:00 2001 From: Chris Bednarski Date: Tue, 17 Nov 2015 21:34:07 -0800 Subject: [PATCH] Renamed some things so it's more apparent that reserved and dynamic port mapping have very similar code --- client/driver/docker.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/client/driver/docker.go b/client/driver/docker.go index f0993b3bc..4b7dbee56 100644 --- a/client/driver/docker.go +++ b/client/driver/docker.go @@ -256,42 +256,42 @@ func (d *DockerDriver) createContainer(ctx *ExecContext, task *structs.Task, dri for _, port := range network.ReservedPorts { hostPortStr := strconv.Itoa(port.Value) - dockerPort := docker.Port(hostPortStr) + containerPort := docker.Port(hostPortStr) - publishedPorts[dockerPort+"/tcp"] = []docker.PortBinding{docker.PortBinding{HostIP: network.IP, HostPort: hostPortStr}} - publishedPorts[dockerPort+"/udp"] = []docker.PortBinding{docker.PortBinding{HostIP: network.IP, HostPort: hostPortStr}} + publishedPorts[containerPort+"/tcp"] = []docker.PortBinding{docker.PortBinding{HostIP: network.IP, HostPort: hostPortStr}} + publishedPorts[containerPort+"/udp"] = []docker.PortBinding{docker.PortBinding{HostIP: network.IP, HostPort: hostPortStr}} d.logger.Printf("[DEBUG] driver.docker: allocated port %s:%d -> %d (static)", network.IP, port.Value, port.Value) - exposedPorts[dockerPort+"/tcp"] = struct{}{} - exposedPorts[dockerPort+"/udp"] = struct{}{} + exposedPorts[containerPort+"/tcp"] = struct{}{} + exposedPorts[containerPort+"/udp"] = struct{}{} d.logger.Printf("[DEBUG] driver.docker: exposed port %d", port.Value) } containerToHostPortMap := make(map[string]int) for _, port := range network.DynamicPorts { // By default we will map the allocated port 1:1 to the container - containerPort := port.Value + containerPortInt := port.Value // If the user has mapped a port using port_map we'll change it here if len(driverConfig.PortMap) == 1 { mapped, ok := driverConfig.PortMap[0][port.Label] if ok { - containerPort = mapped + containerPortInt = mapped } } - containerPortStr := docker.Port(strconv.Itoa(containerPort)) hostPortStr := strconv.Itoa(port.Value) + containerPort := docker.Port(hostPortStr) - publishedPorts[containerPortStr+"/tcp"] = []docker.PortBinding{docker.PortBinding{HostIP: network.IP, HostPort: hostPortStr}} - publishedPorts[containerPortStr+"/udp"] = []docker.PortBinding{docker.PortBinding{HostIP: network.IP, HostPort: hostPortStr}} - d.logger.Printf("[DEBUG] driver.docker: allocated port %s:%d -> %d (mapped)", network.IP, port.Value, containerPort) + publishedPorts[containerPort+"/tcp"] = []docker.PortBinding{docker.PortBinding{HostIP: network.IP, HostPort: hostPortStr}} + publishedPorts[containerPort+"/udp"] = []docker.PortBinding{docker.PortBinding{HostIP: network.IP, HostPort: hostPortStr}} + d.logger.Printf("[DEBUG] driver.docker: allocated port %s:%d -> %d (mapped)", network.IP, port.Value, containerPortInt) - exposedPorts[containerPortStr+"/tcp"] = struct{}{} - exposedPorts[containerPortStr+"/udp"] = struct{}{} + exposedPorts[containerPort+"/tcp"] = struct{}{} + exposedPorts[containerPort+"/udp"] = struct{}{} d.logger.Printf("[DEBUG] driver.docker: exposed port %s", hostPortStr) - containerToHostPortMap[string(containerPortStr)] = port.Value + containerToHostPortMap[string(containerPort)] = port.Value } env.SetPorts(containerToHostPortMap)