Finding available network resources inside your container

Sometimes you may have trouble connecting to a networked resource in your container, such as database images connected as service containers. A simple way to discover the available connections within your container is to use nmap. Specifically the command nmap -v -A localhost

 When you run this command it will scan available ports to see which ones are open, and sometimes provide useful information about the service behind it. In the example below nmap has found an instance of MySQL running on port 3306 while also providing some information about the instance. It has also found a service running on port 5432 and correctly guessed that it's an instance of Postgres running. 

It is not installed by default so you'll need to install it first before running it in your config



- run: sudo apt install nmap -y
- run: nmap -v -A localhost



#!/bin/bash -eo pipefail
nmap -v -A localhost

Starting Nmap 6.47 ( ) at 2017-10-04 18:19 UTC
NSE: Loaded 118 scripts for scanning.
NSE: Script Pre-scanning.
Initiating Ping Scan at 18:19
Scanning localhost ( [2 ports]
Stats: 0:00:00 elapsed; 0 hosts completed (0 up), 1 undergoing Ping Scan
Ping Scan Timing: About 100.00% done; ETC: 18:19 (0:00:00 remaining)
Completed Ping Scan at 18:19, 0.00s elapsed (1 total hosts)
Initiating Connect Scan at 18:19
Scanning localhost ( [1000 ports]
Discovered open port 3306/tcp on
Discovered open port 5432/tcp on
Completed Connect Scan at 18:19, 0.02s elapsed (1000 total ports)
Initiating Service scan at 18:19
Scanning 2 services on localhost (
Completed Service scan at 18:19, 6.02s elapsed (2 services on 1 host)
NSE: Script scanning
Initiating NSE at 18:19
Completed NSE at 18:19, 0.01s elapsed
Nmap scan report for localhost (
Host is up (0.00034s latency).
Other addresses for localhost (not scanned):
Not shown: 998 closed ports
3306/tcp open  mysql       MySQL 5.7.18
| mysql-info: 
|   Protocol: 53
|   Version: .7.18
|   Thread ID: 5
|   Capabilities flags: 65535
|   Some Capabilities: SupportsLoadDataLocal, IgnoreSpaceBeforeParenthesis, Speaks41ProtocolNew, SupportsCompression, Support41Auth, SwitchToSSLAfterHandshake, FoundRows, LongPassword, LongColumnFlag, IgnoreSigpipes, SupportsTransactions, InteractiveClient, DontAllowDatabaseTableColumn, Speaks41ProtocolOld, ODBCClient, ConnectWithDatabase
|   Status: Autocommit
|_  Salt: W\x1Ff&}Wzg/\x02BrhX\x1E\x1Cm+\x1F!
5432/tcp open  postgresql?
1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at :

NSE: Script Post-scanning.
Read data files from: /usr/bin/../share/nmap
Service detection performed. Please report any incorrect results at .
Nmap done: 1 IP address (1 host up) scanned in 6.28 seconds
Was this article helpful?
0 out of 1 found this helpful



Please sign in to leave a comment.