Skip to content

Commit

Permalink
Add a Docker Compose example with Haproxy and an echo server (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
kzemek authored Mar 24, 2024
1 parent f590cae commit 6b2af7e
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.dockerignore
.git
.github
.gitignore
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ Example invocation:
sudo ./go-mmproxy -l 0.0.0.0:25577 -4 127.0.0.1:25578 -6 [::1]:25578 --allowed-subnets ./net-prefixes.txt
```

### Docker examples

You can find an example Dockerfile and a Docker Compose setup in the [docker-example directory](https://github.com/kzemek/go-mmproxy/tree/main/docker-example).

## Benchmark

### Setup
Expand Down
6 changes: 6 additions & 0 deletions docker-example/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM golang:1.21 AS builder
RUN apt-get update && apt-get install -y iptables iproute2 && apt-get clean
WORKDIR /app/src/go-mmproxy
COPY . .
RUN CGO_ENABLED=0 go build -v
ENTRYPOINT ["sh", "-x", "docker-example/entrypoint.sh"]
2 changes: 2 additions & 0 deletions docker-example/Dockerfile.echo
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM ubuntu
RUN apt-get update && apt-get install -y ncat iproute2 tcpdump inetutils-ping iptables && apt-get clean
35 changes: 35 additions & 0 deletions docker-example/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
services:
echo:
build:
context: .
dockerfile: Dockerfile.echo
command: ip route replace default via 10.5.5.3 && ncat -kvnl -e /bin/cat 0.0.0.0 9000
cap_add: [ NET_ADMIN ]
networks:
backend:
ipv4_address: 10.5.5.2

go-mmproxy:
build:
context: ../
dockerfile: docker-example/Dockerfile
command: ./go-mmproxy -l 0.0.0.0:1234 -4 10.5.5.2:9000 -p tcp -v 2 -mark 123
privileged: true
networks:
backend:
ipv4_address: 10.5.5.3
default:


haproxy:
image: haproxy:2.9
ports: [ 8000:8000 ]
volumes:
- ./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg

networks:
backend:
ipam:
config:
- subnet: 10.5.5.0/24
gateway: 10.5.5.1
12 changes: 12 additions & 0 deletions docker-example/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
echo 1 > /proc/sys/net/ipv4/conf/all/route_localnet

# Outgoing packets
iptables -t mangle -A OUTPUT -m mark --mark 123 -j CONNMARK --save-mark
iptables -t mangle -A OUTPUT -m mark --mark 123 -j MARK --set-mark 0
# Incoming packets
iptables -t mangle -A PREROUTING -m connmark --mark 123 -j CONNMARK --restore-mark

ip rule add fwmark 123 lookup 100
ip route add local 0.0.0.0/0 dev lo table 100

env "$@"
7 changes: 7 additions & 0 deletions docker-example/haproxy.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
frontend myfrontend
bind :8000
default_backend mybackend

backend mybackend
balance roundrobin
server go-mmproxy-v1 go-mmproxy:1234 send-proxy

0 comments on commit 6b2af7e

Please sign in to comment.