From 308511a7a37c40654cbbd166fc932d14969f7899 Mon Sep 17 00:00:00 2001 From: Newnius Date: Mon, 18 Feb 2019 15:14:12 +0800 Subject: [PATCH] add port forwarder --- port-forward/Dockerfile | 13 +++++++++++++ port-forward/README.md | 29 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 port-forward/Dockerfile create mode 100644 port-forward/README.md diff --git a/port-forward/Dockerfile b/port-forward/Dockerfile new file mode 100644 index 0000000..ad87135 --- /dev/null +++ b/port-forward/Dockerfile @@ -0,0 +1,13 @@ +FROM alpine:3.8 + +MAINTAINER Newnius + +ARG DEF_REMOTE_PORT=80 +ARG DEF_LOCAL_PORT=80 + +ENV REMOTE_PORT=$DEF_REMOTE_PORT +ENV LOCAL_PORT=$DEF_LOCAL_PORT + +RUN apk add --no-cache socat + +CMD socat tcp-listen:$LOCAL_PORT,reuseaddr,fork tcp:$REMOTE_HOST:$REMOTE_PORT diff --git a/port-forward/README.md b/port-forward/README.md new file mode 100644 index 0000000..b00a62b --- /dev/null +++ b/port-forward/README.md @@ -0,0 +1,29 @@ +port-forward +========================== +Forward your traffic behind NAT, expose certain services in containers etc. + +## Usage + +Define the following environment variables to configure port-forwarding. + +Variable | Description | Optional +-------- | ----------- | -------- +REMOTE_HOST | IP or address of the host you want to forward traffic to | no +REMOTE_PORT | Port on remote host to forward traffic to | yes (80) +LOCAL_PORT | Port where container listens | yes (80) + +The `socat` process within the container will listen by default to port 80, use `-p`docker +flag to map the port of the local machine where it will listen to traffic to be forwarded. + + +```bash +docker run \ + --name port-forward \ + -d \ + --restart always \ + --publish 81:80 \ + --ENV REMOTE_HOST=example.com \ + --ENV REMOTE_PORT=82 \ + --ENV LOCAL_POST=80 \ + newnius/port-forward +```