|
| 1 | +configs: |
| 2 | + ts-serve: |
| 3 | + content: | |
| 4 | + {"TCP":{"443":{"HTTPS":true}}, |
| 5 | + "Web":{"$${TS_CERT_DOMAIN}:443": |
| 6 | + {"Handlers":{"/": |
| 7 | + {"Proxy":"http://127.0.0.1:22300"}}}}, |
| 8 | + "AllowFunnel":{"$${TS_CERT_DOMAIN}:443":false}} |
| 9 | +
|
| 10 | +services: |
| 11 | +# Make sure you have updated/checked the .env file with the correct variables. |
| 12 | +# Every variable used in this file must be defined there, unless it has a default such as ${VAR:-value}. |
| 13 | + # Tailscale Sidecar Configuration |
| 14 | + tailscale: |
| 15 | + image: tailscale/tailscale:latest # Image to be used |
| 16 | + container_name: tailscale-${SERVICE} # Name for local container management |
| 17 | + hostname: ${SERVICE} # Name used within your Tailscale environment |
| 18 | + environment: |
| 19 | + - TS_AUTHKEY=${TS_AUTHKEY} |
| 20 | + - TS_STATE_DIR=/var/lib/tailscale |
| 21 | + - TS_SERVE_CONFIG=/config/serve.json # Tailscale Serve configuration to expose the web interface on your local Tailnet - remove this line if not required |
| 22 | + - TS_USERSPACE=false |
| 23 | + - TS_ENABLE_HEALTH_CHECK=true # Enable healthcheck endpoint: "/healthz" |
| 24 | + - TS_LOCAL_ADDR_PORT=127.0.0.1:41234 # The <addr>:<port> for the healthz endpoint |
| 25 | + #- TS_ACCEPT_DNS=true # Uncomment only if the service must resolve MagicDNS names - this replaces Docker DNS, so Compose service names no longer resolve |
| 26 | + - TS_AUTH_ONCE=true |
| 27 | + configs: |
| 28 | + - source: ts-serve |
| 29 | + target: /config/serve.json |
| 30 | + volumes: |
| 31 | + - ./config:/config # Config folder used to store Tailscale files - you may need to change the path |
| 32 | + - ./ts/state:/var/lib/tailscale # Tailscale requirement - you may need to change the path |
| 33 | + devices: |
| 34 | + - /dev/net/tun:/dev/net/tun # Network configuration for Tailscale to work |
| 35 | + cap_add: |
| 36 | + - net_admin # Tailscale requirement |
| 37 | + #ports: |
| 38 | + # - 0.0.0.0:${SERVICEPORT}:${SERVICEPORT} # Binding the service port to the local network - may be removed if only exposure to your Tailnet is required |
| 39 | + # If any DNS issues arise, use your preferred DNS provider by uncommenting the config below |
| 40 | + #dns: |
| 41 | + # - ${DNS_SERVER} |
| 42 | + healthcheck: |
| 43 | + test: ["CMD", "wget", "--spider", "-q", "http://127.0.0.1:41234/healthz"] # Check Tailscale has a Tailnet IP and is operational |
| 44 | + interval: 1m # How often to perform the check |
| 45 | + timeout: 10s # Time to wait for the check to succeed |
| 46 | + retries: 3 # Number of retries before marking as unhealthy |
| 47 | + start_period: 10s # Time to wait before starting health checks |
| 48 | + restart: always |
| 49 | + |
| 50 | + # Application |
| 51 | + application: |
| 52 | + image: ${IMAGE_URL} # Image to be used |
| 53 | + network_mode: service:tailscale # Sidecar configuration to route the service through Tailscale |
| 54 | + container_name: app-${SERVICE} # Name for local container management |
| 55 | + environment: # Variables are declared in .env file. |
| 56 | + - APP_PORT=22300 |
| 57 | + - APP_BASE_URL=https://${SERVICE}.${TAILNET_NAME:?Set TAILNET_NAME in .env}.ts.net |
| 58 | + - DB_CLIENT=pg |
| 59 | + # POSTGRES_HOST stays unset: Joplin then connects to localhost. Setting it to localhost or 127.0.0.1 makes Joplin use host.docker.internal. |
| 60 | + - POSTGRES_PORT=5432 |
| 61 | + - POSTGRES_USER=joplin |
| 62 | + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env} |
| 63 | + - POSTGRES_DATABASE=joplin |
| 64 | + - TZ=${TZ} |
| 65 | + depends_on: |
| 66 | + tailscale: |
| 67 | + condition: service_healthy |
| 68 | + db: |
| 69 | + condition: service_healthy |
| 70 | + # Joplin answers only requests whose Host header matches APP_BASE_URL, so the check sends that host to the public /api/ping endpoint. |
| 71 | + healthcheck: |
| 72 | + test: ["CMD", "node", "-e", "require('http').get('http://127.0.0.1:22300/api/ping',{headers:{Host:new URL(process.env.APP_BASE_URL).host}},r=>process.exit(r.statusCode===200?0:1)).on('error',()=>process.exit(1))"] # Check if the service is responding |
| 73 | + interval: 1m # How often to perform the check |
| 74 | + timeout: 10s # Time to wait for the check to succeed |
| 75 | + retries: 3 # Number of retries before marking as unhealthy |
| 76 | + start_period: 60s # Time to wait before starting health checks |
| 77 | + restart: always |
| 78 | + |
| 79 | + # Database |
| 80 | + db: |
| 81 | + image: postgres:16 |
| 82 | + network_mode: service:tailscale # Join the same network namespace to be accessible via localhost |
| 83 | + container_name: app-${SERVICE}-db # Name for local container management |
| 84 | + command: ["postgres", "-c", "listen_addresses=localhost"] # Listen on localhost only, so the Tailnet cannot reach the database |
| 85 | + environment: |
| 86 | + - POSTGRES_USER=joplin |
| 87 | + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env} |
| 88 | + - POSTGRES_DB=joplin |
| 89 | + volumes: |
| 90 | + - ./${SERVICE}-data/db:/var/lib/postgresql/data |
| 91 | + healthcheck: |
| 92 | + test: ["CMD-SHELL", "pg_isready -h 127.0.0.1 -U joplin -d joplin"] # Check if PostgreSQL accepts connections |
| 93 | + interval: 10s # How often to perform the check |
| 94 | + timeout: 5s # Time to wait for the check to succeed |
| 95 | + retries: 5 # Number of retries before marking as unhealthy |
| 96 | + start_period: 30s # Time to wait before starting health checks |
| 97 | + restart: always |
0 commit comments