almeidapaulopt / tsdproxy

Tailscale Docker Proxy
MIT License
114 stars 5 forks source link
docker go self-hosted tailscale

TsDProxy - Tailscale Docker Proxy

This Docker-based application automatically creates a proxy to virtual addresses in your Tailscale network based on Docker container labels. It simplifies traffic redirection to services running inside Docker containers, without the need for a separate Tailscale container for each service.

Documentation

https://almeidapaulopt.github.io/tsdproxy/

Features

Requirements

Before using this application, make sure you have:

Configuration

This application scans running Docker containers for specific labels to configure proxies to Tailscale virtual addresses.

Example Labels for a Docker Container

Add the following labels to the Docker containers you wish to proxy:

labels:
  - "tsdproxy.enable=true"
  - "tsdproxy.name=example"
  - "tsdproxy.container_port=80"

Running the Tailscale Docker Proxy

To run the TsDProxy itself, use the following Docker command:

docker run -d --name tsdproxy -v /var/run/docker.sock:/var/run/docker.sock almeidapaulopt/tsdproxy:latest

Example Docker Compose Setup

Here’s an example of how you can configure your services using Docker Compose:

TsDProxy docker-compose.yaml

services:
  tailscale-docker-proxy:
    image: almeidapaulopt/tsdproxy:latest
    container_name: tailscale-docker-proxy
    ports:
      - "80:8080"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - datadir:/data
    restart: unless-stopped
    environment:
      - TSDPROXY_AUTHKEY=tskey-auth-SecretKey
      - TSDPROXY_HOSTNAME=server1 # Address of docker server (access to example.com ports)
      - DOCKER_HOST=unix:///var/run/docker.sock
      #- TSDPROXY_AUTHKEYFILE=/run/secrets/authkey # to use docker secrets, Don't use AUTHKEY 
      #- TSDPROXY_DATADIR:/data # defaults to /data
      #- TSDPROXY_LOGLEVEL=info 
      #- TSDPROXY_CONTAINERACCESSLOG=true #enable proxy access log for all active containers

      #secrets:
      #- authkey

#secrets:
  #  authkey:
    #file: tsdproxy_authkey.txt

volumes:
  datadir:

YourService docker-compose.yaml

services:
  my-service:
    image: my-service-image
    labels:
      - "tsdproxy.enable=true"
    ports:
      - "8080:8080"

How It Works

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests to help improve the app.