From b6985f690c1b4cc8374f1fd2cac36ec843a79bf5 Mon Sep 17 00:00:00 2001 From: Prashanth <30420973+PrashanthCorp@users.noreply.github.com> Date: Tue, 14 Aug 2018 10:55:33 -0700 Subject: [PATCH] Change getExposedPorts to return port w/ protocol (#349) * Change getExposedPorts to return port w/ protocol * member ordering * Add comment to explain using the port prefix --- commands/start-container.ts | 3 ++- commands/utils/docker-endpoint.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/commands/start-container.ts b/commands/start-container.ts index 30e19b80a8..bc3496cee7 100644 --- a/commands/start-container.ts +++ b/commands/start-container.ts @@ -29,7 +29,8 @@ export async function startContainer(context?: ImageNode, interactive?: boolean) docker.getExposedPorts(imageToStart.Id).then((ports: string[]) => { let options = `--rm ${interactive ? '-it' : '-d'}`; if (ports.length) { - const portMappings = ports.map((port) => `-p ${port}:${port}`); + const portMappings = ports.map((port) => `-p ${port.split("/")[0]}:${port}`); //'port' is of the form number/protocol, eg. 8080/udp. + // In the command, the host port has just the number (mentioned in the EXPOSE step), while the destination port can specify the protocol too options += ` ${portMappings.join(' ')}`; } diff --git a/commands/utils/docker-endpoint.ts b/commands/utils/docker-endpoint.ts index c053d87162..3b82f2afa2 100644 --- a/commands/utils/docker-endpoint.ts +++ b/commands/utils/docker-endpoint.ts @@ -107,7 +107,7 @@ class DockerClient { public getExposedPorts(imageId: string): Thenable { return new Promise((resolve, reject) => { this.getImage(imageId).inspect((error, { Config: { ExposedPorts = {} } }) => { - const ports = Object.keys(ExposedPorts).map((port) => port.split("/")[0]); + const ports = Object.keys(ExposedPorts); resolve(ports); }); });