Skip to content

Instantly share code, notes, and snippets.

@atomatt
Created December 3, 2020 10:47
Show Gist options
  • Select an option

  • Save atomatt/94bf0b8222bd19865991f2f0e61bd342 to your computer and use it in GitHub Desktop.

Select an option

Save atomatt/94bf0b8222bd19865991f2f0e61bd342 to your computer and use it in GitHub Desktop.
TCP proxy from host to service port in a docker container
#!/usr/bin/env bash
set -eu
network="${1:?network is required}"
service_name="${2:?service name is required}"
service_port="${3:?service port is required}"
host_port="${4:-${service_port}}"
docker run --rm \
--network "${network}" \
-p "${host_port}":"${service_port}" \
nixery.dev/socat socat \
"TCP-LISTEN:${service_port},fork" "TCP:${service_name}:${service_port}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment