Doing It Wrong

learn in public

Site Navigation

  • Home
  • Books
  • Work & Play

Site Search

You are here: Home / Work & Play

Work & Play

re-ports

Recursively finds docker-compose ‘ports’ declarations and prints to stdout as CSV.

  • GitHub
  • npm
details about re-ports

This goofy little script was a chance for me to explore generator functions in JavaScript. At the place I work, there was a security directive to not expose ports from your localhost to the broader internet. If you don’t know, Docker’s “default” port declarations, e.g., 80:8080, will bind the Docker network’s 8080 to your public IP address’ port 80 (Jeff Geerling has an excellent article on this). Try it out!

  1. find your public IP address (Nord VPN’s tool should work)
  2. start your Docker container
  3. visit your public IP address + port, e.g., 123.456.789.123:80
  4. be afraid…
  5. fix your port declarations by adding your localhost IP address to your port declarations, e.g., "127.0.0.1:80:8080"

So anyway, this silly CLI1 tool will recursively search through the path you give it for /docker-compose.*.yml$/2, printing to stdout the ports declarations it finds in CSV format. Because I used generator functions, the code lazily evaluates the recursive tree

  • loading only what needs to be held in memory
  • processing files as they are evaluated (instead of needing to first load the entire tree)
  1. Command-Line Interface ↩︎
  2. Use Regex101 to see what this matches. ↩︎

Profile Links

  • GitHub
  • Buy Me a Coffee?

Recent Posts

  • Event Listeners
  • A Philosophy of Software Design
  • The Programmer’s Brain
  • Thoughts on Microservices
  • API Design Patterns

Recent Comments

No comments to show.

Archives

  • May 2025
  • September 2024
  • July 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • December 2022
  • December 2021

Categories

  • Development