Skip to content

Use docker compose

Jason Lyu edited this page Apr 3, 2022 · 5 revisions

Notes

We must use docker-compose version 2, since version 3 doesn't support user to specify network gateways.

Example

docker-compose.yml

version: '2.4'

services:
  tun2socks:
    image: ghcr.io/xjasonlyu/tun2socks:latest
    mem_limit: 1000000000
    memswap_limit: 2000000000
    mem_reservation: 512m
    cap_add:
      - NET_ADMIN
    devices:
        - '/dev/net/tun:/dev/net/tun'
    environment:
      - LOGLEVEL=info             # default
      - TUN=tun0                  # default
      - ADDR=198.18.0.1/15        # default
      - MTU=9000                  # default
      - PROXY=                    # *required
      - STATS=:8080               # optional
      - RESTAPI=                  # optional
      - TCP_SNDBUF=.              # optional
      - TCP_RCVBUF=.              # optional
      - TCP_AUTO_TUNING=.         # optional
      - UDP_TIMEOUT=              # optional
      - EXTRA_COMMANDS=           # optional
      - TUN_INCLUDED_ROUTES=      # optional
      - TUN_EXCLUDED_ROUTES=      # optional
      # - GODEBUG=madvdontneed=1  # optional
    networks:
      switch:
        ipv4_address: 172.20.1.2
    sysctls:
      - net.ipv4.ip_forward=1
      # - net.ipv4.conf.all.rp_filter=0
    restart: unless-stopped
    container_name: tun2socks

networks:
  switch:
    name: switch
    ipam:
      driver: default
      config:
        - subnet: '172.20.1.0/25'
          gateway: 172.20.1.1
    driver: macvlan
    driver_opts:
      parent: eth0

Start

docker-compose up -d
Clone this wiki locally