From 44ac6e9295f213707709d38ed1d7c55969a06c83 Mon Sep 17 00:00:00 2001 From: Ahmad Wilson Date: Fri, 24 Mar 2017 20:18:12 +0000 Subject: [PATCH] Refactor exposed port identification The previous mechanism for identifying exposed ports on host machines was flakey and not really an ideal/efficient means of identifying exposed ports (i.e attempting to connect to port with a 1 second timeout). This change modifies the method to make use of netstat and varies the usage based on the host OS appropriately. --- Dockerfile | 2 +- bin/dock | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 72bc5c5..81d93ae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ RUN yum -y install \ # Docker daemon won't start without `iptables` installed iptables-services \ # Used for a variety of simple tests for port forwarding/publishing - nmap-ncat \ + nmap-ncat net-tools \ # Allow `dock-user` to escalate privileges if necessary sudo \ # Allow us to run using OverlayFS file system diff --git a/bin/dock b/bin/dock index dad3b23..48f3be8 100755 --- a/bin/dock +++ b/bin/dock @@ -693,7 +693,12 @@ destroy_container() { } port_taken_on_localhost() { - echo | nc -w 1 localhost $1 >/dev/null 2>&1 + if osx; then + # show -a(ll sockets) and -n(umeric addresses) + echo | netstat -a -n 2>/dev/null | grep $1 >/dev/null 2>&1 + else + echo | netstat --numeric --listening 2>/dev/null | grep $1 >/dev/null 2>&1 + fi } process_exposed_ports() {