Standard patterns for deploying services on linuxserver.lan / ai-servicers.com
#!/bin/bash
set -e # Exit on error
# ===== Configuration =====
PROJECT_DIR="/home/administrator/projects/myservice"
SECRETS_FILE="$HOME/projects/secrets/myservice.env"
DATA_DIR="$HOME/projects/data/myservice"
# ===== Validate Secrets =====
if [ ! -f "$SECRETS_FILE" ]; then
echo "ERROR: Secrets file not found"
exit 1
fi
source "$SECRETS_FILE"
# ===== Create Directories =====
mkdir -p "$DATA_DIR"
# ===== Create Networks =====
docker network create traefik-net 2>/dev/null || true
docker network create myservice-net 2>/dev/null || true
# ===== Stop Existing =====
docker stop myservice 2>/dev/null || true
docker rm myservice 2>/dev/null || true
# ===== Deploy Container =====
docker run -d \
--name myservice \
--restart unless-stopped \
--network traefik-net \
-v "$DATA_DIR:/data" \
-e SECRET_KEY="$SECRET_KEY" \
--label "traefik.enable=true" \
--label "traefik.http.routers.myservice.rule=Host(\`myservice.ai-servicers.com\`)" \
--label "traefik.http.routers.myservice.entrypoints=websecure" \
--label "traefik.http.routers.myservice.tls.certresolver=letsencrypt" \
--label "traefik.http.services.myservice.loadbalancer.server.port=8080" \
myimage:latest
# ===== Connect Additional Networks =====
docker network connect myservice-net myservice
echo "Deployed: https://myservice.ai-servicers.com"
For services requiring SSO authentication
Examples: grafana, portainer, obsidian, dashy
For services needing database connectivity
Examples: keycloak, nextcloud, openproject
For standalone web services
Examples: static sites, simple APIs, tools
traefik-netkeycloak-net + deploy OAuth2 proxypostgres-netredis-netmongodb-netmcp-net| Label | Purpose | Example Value |
|---|---|---|
| traefik.enable | Enable Traefik routing | true |
| traefik.http.routers.[name].rule | Routing rule (hostname) | Host(`service.ai-servicers.com`) |
| traefik.http.routers.[name].entrypoints | Entry point (HTTP/HTTPS) | websecure |
| traefik.http.routers.[name].tls.certresolver | SSL certificate provider | letsencrypt |
| traefik.http.services.[name].loadbalancer.server.port | Container port to route to | 8080 |
| traefik.docker.network | Network for routing (when on multiple) | traefik-net |
If your container is on multiple networks, you MUST specify traefik.docker.network=traefik-net or Traefik may pick the wrong network and fail to route.
# /home/administrator/projects/secrets/myservice.env
# Container settings
PUID=1000
PGID=1000
TZ=America/New_York
# Application secrets
SECRET_KEY=your-secret-here
DATABASE_URL=postgres://user:pass@postgres:5432/db
# OAuth2 (if protected)
OAUTH2_PROXY_CLIENT_ID=myservice
OAUTH2_PROXY_CLIENT_SECRET=keycloak-secret
OAUTH2_PROXY_COOKIE_SECRET=32-byte-secret
For full details, see Security & Auth Documentation
docker run -d \
--name myservice-auth-proxy \
--network traefik-net \
--network keycloak-net \
-e OAUTH2_PROXY_PROVIDER=keycloak-oidc \
-e OAUTH2_PROXY_CLIENT_ID="$CLIENT_ID" \
-e OAUTH2_PROXY_CLIENT_SECRET="$CLIENT_SECRET" \
-e OAUTH2_PROXY_COOKIE_SECRET="$COOKIE_SECRET" \
-e OAUTH2_PROXY_UPSTREAMS="http://myservice:8080/" \
-e OAUTH2_PROXY_SKIP_OIDC_DISCOVERY=true \
-e OAUTH2_PROXY_OIDC_ISSUER_URL="https://keycloak.ai-servicers.com/realms/master" \
-e OAUTH2_PROXY_LOGIN_URL="https://keycloak.ai-servicers.com/realms/master/protocol/openid-connect/auth" \
-e OAUTH2_PROXY_REDEEM_URL="http://keycloak:8080/realms/master/protocol/openid-connect/token" \
-e OAUTH2_PROXY_OIDC_JWKS_URL="http://keycloak:8080/realms/master/protocol/openid-connect/certs" \
--label "traefik.enable=true" \
--label "traefik.http.routers.myservice.rule=Host(\`myservice.ai-servicers.com\`)" \
quay.io/oauth2-proxy/oauth2-proxy:latest
mkdir -p /home/administrator/projects/[service]
Create /home/administrator/projects/secrets/[service].env with required variables
mkdir -p /home/administrator/projects/data/[service]
Use the pattern above, customize for your service
Create client in Keycloak, add secret to env file
./deploy.sh && docker logs [service] --tail 20
curl -I https://[service].ai-servicers.com
Document the service for AI context
# Deploy/redeploy
cd /home/administrator/projects/[service]
./deploy.sh
# Check status
docker ps | grep [service]
# View logs
docker logs [service] --tail 50 -f
# Restart
docker restart [service]
# Stop and remove
docker stop [service] && docker rm [service]
# Check container networks
docker inspect [service] \
--format='{{range $k,$v:=.NetworkSettings.Networks}}{{$k}} {{end}}'
# Test internal connectivity
docker exec [container] ping -c 1 [target]
# Check Traefik routing
curl -I https://[service].ai-servicers.com
# View Traefik logs
docker logs traefik --tail 50 | grep [service]