2018/12/04

Mapping Private/Public Docker ports with AWS ECS and Docker Net=Bridge

I've done many searches trying to find a way to know what the public port numbers that have been assigned to my docker container are from inside the container. Docker has a way to query this information but that means exposing the Docker Daemon interface (socket or tcp) to the process running inside the container and sadly there are little security controls around that so understandably most are reluctant to expose that interface inside the container

Amazon's ECS agent has a lightweight which will expose details about the container which happens to include the Private/Public port mappings. I've included a link to the script I wrote here GitHub Gist along with the code below.

It requires the use of JQ which I happen to consider a fundamental tool if your going to manipulate JSON files from within bash.