diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0b95fa6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +node_modules/ +tmp/ +vendor/ + +*.bak +*.log +*.orig +*.rej +*.tmp +*~ + +docker-compose.override.yml diff --git a/projects/traefik/README.md b/projects/traefik/README.md new file mode 100644 index 0000000..33b9328 --- /dev/null +++ b/projects/traefik/README.md @@ -0,0 +1,37 @@ +# Docker Network Proxy + +## Quick Start + + bin/up + echo "127.0.0.1 api.aspiredev.org staging.aspiredev.org" | sudo tee -a /etc/hosts + echo "::1 api.aspiredev.org staging.aspiredev.org" | sudo tee -a /etc/hosts + +_(Windows users, **including WSL2**: edit `C:\Windows\System32\drivers\etc\hosts` instead of /etc/hosts)_ + +## Enabling the proxy in docker-compose.yml + +Add the following to the service you want proxied, substituting `myservice` and `myhostname.local` appropriately + +`myservice` can be anything you want, but it must be unique across all your docker containers + + labels: + - "traefik.enable=true" + - "traefik.http.routers.myservice.rule=Host(`myhostname.local`)" + - "traefik.http.routers.myservice-https.rule=Host(`myhostname.local`)" + - "traefik.http.routers.myservice-https.tls=true" + networks: + - traefik + +Add the following to the top level keys + + networks: + traefik: + external: true + +Finally, add the following lines to your `/etc/hosts` file (`C:\Windows\System32\drivers\etc\hosts` on Windows) + +``` +127.0.0.1 myhostname.local +::1 myhostname.local +``` + diff --git a/projects/traefik/bin/down b/projects/traefik/bin/down new file mode 100755 index 0000000..2e1954b --- /dev/null +++ b/projects/traefik/bin/down @@ -0,0 +1,5 @@ +#!/bin/sh + +cd $(dirname $0)/.. + +exec docker compose down "$@" diff --git a/projects/traefik/bin/up b/projects/traefik/bin/up new file mode 100755 index 0000000..36fd67c --- /dev/null +++ b/projects/traefik/bin/up @@ -0,0 +1,7 @@ +#!/bin/sh + +cd $(dirname $0)/.. + +docker network create traefik >/dev/null 2>&1 || true + +exec docker compose up -d "$@" \ No newline at end of file diff --git a/projects/traefik/docker-compose.yml b/projects/traefik/docker-compose.yml new file mode 100644 index 0000000..55e4bf7 --- /dev/null +++ b/projects/traefik/docker-compose.yml @@ -0,0 +1,30 @@ +services: + traefik: + image: traefik:3.3.2 + restart: unless-stopped + command: + - "--api.dashboard=true" + - "--api.insecure=true" + - "--log.format=json" + - "--log.level=INFO" + - "--accesslog=true" + - "--accesslog.format=json" + - "--providers.docker.network=traefik" + - "--providers.docker.exposedbydefault=false" + - "--entrypoints.web.address=:80" + - "--entrypoints.web-secure.address=:443" + - "--global.checkNewVersion=false" + - "--global.sendanonymoususage=false" + - "--api.disabledashboardad=true" + ports: + - "${TRAEFIK_HTTP_PORT:-80}:80" + - "${TRAEFIK_HTTPS_PORT:-443}:443" + - "${TRAEFIK_DASHBOARD_PORT:-8080}:8080" + volumes: + - /var/run/docker.sock:/var/run/docker.sock + networks: + - traefik + +networks: + traefik: + external: true