Skip to content

Commit

Permalink
Change getExposedPorts to return port w/ protocol (#349)
Browse files Browse the repository at this point in the history
* Change getExposedPorts to return port w/ protocol

* member ordering

* Add comment to explain using the port prefix
  • Loading branch information
PrashanthCorp authored Aug 14, 2018
1 parent 7c95b8d commit b6985f6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion commands/start-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(' ')}`;
}

Expand Down
2 changes: 1 addition & 1 deletion commands/utils/docker-endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class DockerClient {
public getExposedPorts(imageId: string): Thenable<string[]> {
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);
});
});
Expand Down

0 comments on commit b6985f6

Please sign in to comment.