Created
January 23, 2019 10:22
-
-
Save vierbergenlars/1124e5ce6cf9c9968204fcc91e80128b to your computer and use it in GitHub Desktop.
Bridge a port that is exposed inside a container to your host
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
#!/bin/bash | |
# Call as docker-intercept <container-name> <port-inside-container> <port-on-host> | |
set -e | |
container="$1" | |
container_port="$2" | |
host_port="$3" | |
network_id="$(docker inspect "$container" | jq '.[0].NetworkSettings.Networks | to_entries | .[0].value.NetworkID' -r)" | |
container_ip="$(docker inspect "$container" | jq '.[0].NetworkSettings.Networks | to_entries | .[0].value.IPAddress' -r)" | |
docker run -ti --rm --net "$network_id" -p "$host_port:$host_port" bobrik/socat "TCP4-LISTEN:$host_port,fork,bind=0.0.0.0" "TCP4:$container_ip:$container_port" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment