diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..59479b6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +#################################################################################################### +## Builder +#################################################################################################### +FROM rust:latest AS builder + +WORKDIR /worker +COPY ./ . +RUN cargo build --release --target x86_64-unknown-linux-gnu + + +#################################################################################################### +## Final image +#################################################################################################### +FROM ubuntu:latest +WORKDIR /app + +ENV TUN=tun0 +ENV PROXY= +ENV DNS=virtual +ENV MODE=auto +ENV BYPASS_IP= + +RUN apt update && apt install -y iproute2 curl && apt clean all + +COPY --from=builder /worker/target/x86_64-unknown-linux-gnu/release/tun2proxy /usr/bin/tun2proxy +COPY --from=builder /worker/docker/entrypoint.sh /app + +ENTRYPOINT ["/app/entrypoint.sh"] diff --git a/README.md b/README.md index 4b245e0..0c19917 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,30 @@ Currently, tun2proxy supports HTTP, SOCKS4/SOCKS4a and SOCKS5. A proxy is suppli URL format. For example, an HTTP proxy at `1.2.3.4:3128` with a username of `john.doe` and a password of `secret` is supplied as `--proxy http://john.doe:secret@1.2.3.4:3128`. This works analogously to curl's `--proxy` argument. +## Docker Support + +```bash +docker run -d \ + -e PROXY=PROXY_TYPE://PROXY_IP:PROXY_PORT \ + -v /dev/net/tun:/dev/net/tun \ + --sysctl net.ipv6.conf.all.disable_ipv6=0 \ + --sysctl net.ipv6.conf.default.disable_ipv6=0 \ + --cap-add NET_ADMIN \ + --name tun2proxy \ + image:tags +``` + +Provide a network to another worker container. (share netns). + +```bash +docker run -it \ + -d \ + --network "container:tun2proxy" \ + worker-example:tags +``` + + + ## Configuration Tips ### DNS When DNS resolution is performed by a service on your machine or through a server in your local network, DNS resolution diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100644 index 0000000..a923180 --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,29 @@ +#!/bin/bash + + +run() { + if [ -n "$BYPASS_IP" ]; then + BYPASS_IP="--bypass-ip $BYPASS_IP" + fi + + if [ -n "$DNS" ]; then + DNS="--dns $DNS" + fi + + if [ -n "$MODE" ]; then + MODE="--setup $MODE" + fi + + if [ -n "$PROXY" ]; then + PROXY="--proxy $PROXY" + fi + + if [ -n "$TUN" ]; then + TUN="--tun $TUN" + fi + + exec tun2proxy $TUN $PROXY $DNS $MODE $BYPASS_IP +} + + +run || echo "Runing ERROR!!"