6 changed files with 93 additions and 61 deletions
@ -0,0 +1 @@ |
|||
.gitignore |
|||
@ -0,0 +1,60 @@ |
|||
#################################################################################################### |
|||
# This is a multi-stage Dockerfile. |
|||
# Build with `docker buildx build -t <image-tag> --target <stage> .` |
|||
# For example, to build the Alpine-based image while naming it tun2proxy, run: |
|||
# `docker buildx build -t tun2proxy --target tun2proxy-alpine .` |
|||
#################################################################################################### |
|||
|
|||
#################################################################################################### |
|||
## glibc builder |
|||
#################################################################################################### |
|||
FROM rust:latest AS glibc-builder |
|||
|
|||
WORKDIR /worker |
|||
COPY ./ . |
|||
RUN cargo build --release |
|||
|
|||
#################################################################################################### |
|||
## musl builder |
|||
#################################################################################################### |
|||
FROM rust:latest AS musl-builder |
|||
|
|||
WORKDIR /worker |
|||
COPY ./ . |
|||
RUN rustup target add x86_64-unknown-linux-musl |
|||
RUN cargo build --release --target x86_64-unknown-linux-musl |
|||
|
|||
RUN mkdir /.etc \ |
|||
&& touch /.etc/resolv.conf \ |
|||
&& mkdir /.tmp \ |
|||
&& chmod 777 /.tmp \ |
|||
&& chmod +t /.tmp |
|||
|
|||
#################################################################################################### |
|||
## Alpine image |
|||
#################################################################################################### |
|||
FROM alpine:latest AS tun2proxy-alpine |
|||
|
|||
COPY --from=musl-builder /worker/target/x86_64-unknown-linux-musl/release/tun2proxy-bin /usr/bin/tun2proxy-bin |
|||
|
|||
ENTRYPOINT ["/usr/bin/tun2proxy-bin", "--setup"] |
|||
|
|||
#################################################################################################### |
|||
## Ubuntu image |
|||
#################################################################################################### |
|||
FROM ubuntu:latest AS tun2proxy-ubuntu |
|||
|
|||
COPY --from=glibc-builder /worker/target/release/tun2proxy-bin /usr/bin/tun2proxy-bin |
|||
|
|||
ENTRYPOINT ["/usr/bin/tun2proxy-bin", "--setup"] |
|||
|
|||
#################################################################################################### |
|||
## OS-less image (default) |
|||
#################################################################################################### |
|||
FROM scratch AS tun2proxy-scratch |
|||
|
|||
COPY --from=musl-builder ./tmp /tmp |
|||
COPY --from=musl-builder ./etc /etc |
|||
COPY --from=musl-builder /worker/target/x86_64-unknown-linux-musl/release/tun2proxy-bin /usr/bin/tun2proxy-bin |
|||
|
|||
ENTRYPOINT ["/usr/bin/tun2proxy-bin", "--setup"] |
|||
@ -1,18 +0,0 @@ |
|||
#################################################################################################### |
|||
## Builder |
|||
#################################################################################################### |
|||
FROM rust:latest AS builder |
|||
WORKDIR /worker |
|||
COPY ./ . |
|||
RUN rustup target add x86_64-unknown-linux-musl |
|||
RUN cargo build --release --target x86_64-unknown-linux-musl |
|||
|
|||
#################################################################################################### |
|||
## Final image |
|||
#################################################################################################### |
|||
FROM alpine:latest |
|||
RUN apk add --no-cache iproute2 |
|||
|
|||
COPY --from=builder /worker/target/x86_64-unknown-linux-musl/release/tun2proxy-bin /usr/bin/tun2proxy-bin |
|||
|
|||
ENTRYPOINT ["/usr/bin/tun2proxy-bin", "--setup"] |
|||
@ -1,20 +0,0 @@ |
|||
#################################################################################################### |
|||
## Builder |
|||
#################################################################################################### |
|||
FROM rust:latest AS builder |
|||
|
|||
WORKDIR /worker |
|||
COPY ./ . |
|||
RUN cargo build --release |
|||
|
|||
|
|||
#################################################################################################### |
|||
## Final image |
|||
#################################################################################################### |
|||
FROM ubuntu:latest |
|||
|
|||
RUN apt update && apt install -y iproute2 && apt clean all |
|||
|
|||
COPY --from=builder /worker/target/release/tun2proxy-bin /usr/bin/tun2proxy-bin |
|||
|
|||
ENTRYPOINT ["/usr/bin/tun2proxy-bin", "--setup"] |
|||
@ -177,7 +177,16 @@ supplied as `--proxy http://john.doe:[email protected]:3128`. This works analogousl |
|||
Tun2proxy can serve as a proxy for other Docker containers. To make use of that feature, first build the image: |
|||
|
|||
```bash |
|||
docker build -t tun2proxy . |
|||
docker buildx build -t tun2proxy . |
|||
``` |
|||
|
|||
This will build an image containing a statically linked `tun2proxy` binary (based on `musl`) without OS. |
|||
|
|||
Alternatively, you can build images based on Ubuntu or Alpine as follows: |
|||
|
|||
```bash |
|||
docker buildx build -t tun2proxy --target tun2proxy-ubuntu . |
|||
docker buildx build -t tun2proxy --target tun2proxy-alpine . |
|||
``` |
|||
|
|||
Next, start a container from the tun2proxy image: |
|||
@ -188,7 +197,7 @@ docker run -d \ |
|||
--sysctl net.ipv6.conf.default.disable_ipv6=0 \ |
|||
--cap-add NET_ADMIN \ |
|||
--name tun2proxy \ |
|||
tun2proxy-bin --proxy proto://[username[:password]@]host:port |
|||
tun2proxy --proxy proto://[username[:password]@]host:port |
|||
``` |
|||
|
|||
You can then provide the running container's network to another worker container by sharing the network namespace (like kubernetes sidecar): |
|||
@ -200,7 +209,7 @@ docker run -it \ |
|||
``` |
|||
### Docker Compose |
|||
|
|||
Write a `docker-compose.yaml` file with the following content: |
|||
Create a `docker-compose.yaml` file with the following content: |
|||
|
|||
```yaml |
|||
services: |
|||
|
|||
Loading…
Reference in new issue