Created
April 27, 2021 23:45
-
-
Save stj/2658ed400f80027f214a23589b11238e to your computer and use it in GitHub Desktop.
Reroute dynamic docker port to fixed local port
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pgreroute() { | |
re=':::([0-9]{1,5})->5432'; | |
[[ $(docker ps -f "expose=5432") =~ $re ]]; | |
port=${BASH_REMATCH[1]}; | |
sudo iptables -t nat -I PREROUTING -p tcp --dport 5432 -j REDIRECT --to-ports $port; | |
sudo iptables -t nat -I OUTPUT -p tcp -o lo --dport 5432 -j REDIRECT --to-ports $port; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment