Skip to content

Instantly share code, notes, and snippets.

@DoomHammer
Created November 13, 2018 20:00
Show Gist options
  • Save DoomHammer/259a71397bc05cdf43c07790565b2856 to your computer and use it in GitHub Desktop.
Save DoomHammer/259a71397bc05cdf43c07790565b2856 to your computer and use it in GitHub Desktop.
Docker on Windows port forwarding
#!/bin/sh
# This script uses Virtualbox Port Forwarding to make all Docker services
# available on Windows host under `localhost`
VBXMGMT=/c/Program\ Files/Oracle/VirtualBox/VBoxManage.exe
# List all the running container ids
docker ps -q | while read -r i; do
# List all the ports bound by this container<Paste>
for port in $(docker port "$i" | cut -d'-' -f1); do
port_num=$(echo "${port}" | cut -d'/' -f1)
port_type=$(echo "${port}" | cut -d'/' -f2)
echo "Create rule natpf1 for ${port_type} port ${port_num}"
"$VBXMGMT" controlvm "default" natpf1 "${port_type}-port${port_num},${port_type},,${port_num},,${port_num}"
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment