# はじめに

> [!WARNING]
>
> このページは英語版のほうが新しくなっています。[英語版を読む](<https://geiserx.github.io/CashPilot/getting-started/>)。

## 前提条件

- **Docker** と **Compose v2 プラグインのバージョン 2.23.1 以降**。 `docker compose version` で確認してください。これより古いバージョンは、compose ファイル内のインライン設定を読み込めません。Docker Desktop にはこのプラグインが含まれています。 Linux の素の Docker Engine では、Docker のパッケージリポジトリからインストールしてください ([https://docs.docker.com/compose/install/linux/](<https://docs.docker.com/compose/install/linux/>))。macOS で Colima を使う場合は、 Homebrew でインストールし、Docker プラグインとしてリンクします。

  ```
  brew install docker-compose
  mkdir -p ~/.docker/cli-plugins
  ln -sfn "$(brew --prefix)/opt/docker-compose/bin/docker-compose" ~/.docker/cli-plugins/docker-compose
  ```
- Linux、macOS、または Windows のホスト(amd64 または arm64)
- CashPilot と管理対象のサービス用に、1 GB 以上の空き RAM
- **Docker ホストごとに CashPilot は 1 つだけ。** 下の警告を参照してください。

> [!WARNING]
>
> **Docker ホストごとに CashPilot は 1 つだけ**
>
> 1 台の Docker ホストで CashPilot を 2 つインストールして動かさないでください。compose ファイルは 固定のコンテナ名(`cashpilot-ui`、`cashpilot-worker`、 `cashpilot-socket-proxy`)を使うため、ファイルの 2 つ目のコピーは名前の 衝突で失敗します。これを避けるために名前を変えても、2 つのインストールは 同じホストを共有したままです。各ワーカーは、CashPilot のラベルが付いたすべてのコンテナを、 どちらのインストールが作ったかに関係なく管理します。そのため、それぞれのダッシュボードが もう一方の収益アプリを一覧に表示し、停止し、置き換えてしまいます。2 つは `cashpilot-isolated` ネットワーク、収益アプリの名前(`cashpilot-<service>`)、 ホストのポート、`mysterium-data` などのボリュームも共有します。2 つ目の インストールには、別のホストか VM を使ってください。より多くのサーバーで収益アプリを動かすには、 代わりに 1 つのダッシュボードにワーカーを追加してください([フリート](<https://geiserx.github.io/CashPilot/ja/fleet/index.md>))。

## クイックスタート

### 1\. compose ファイルを取得して起動する

```
curl -fsSLO https://raw.githubusercontent.com/GeiserX/CashPilot/main/docker-compose.yml
docker compose up -d
```

これで常駐するコンテナが 3 つ起動します。その前に、1 回だけ動く `cashpilot-migrate` が `up` のたびに実行され、コード 0 で終了します。そのため `docker compose ps -a` では `Exited (0)` と表示されます。これは正常です。

| コンテナ | ポート | 役割 |
| --- | --- | --- |
| **cashpilot-migrate** | なし | 1 回だけ実行されて終了します。古いリリースが作ったデータを、ソケットプロキシが受け入れるボリュームへ移します。新規インストールでは何もすることがありません |
| **cashpilot-ui** | 8080 | Web ダッシュボード、収益の収集、サービスカタログ |
| **cashpilot-worker** | 8081 | サービスのコンテナをデプロイして監視する Docker エージェント |
| **cashpilot-socket-proxy** | なし | Docker ソケットを保持し、ワーカーにはフィルターをかけたコピーを渡します([セキュリティの既定値](<https://geiserx.github.io/CashPilot/ja/security-defaults/index.md>)) |

### 2\. ダッシュボードを開く

ブラウザーで [http://localhost:8080](<http://localhost:8080>) を開いてください。まだアカウントがないので、ウェルカムページが表示されます。このページでオーナーアカウントを作成します。

> [!TIP]
>
> **ポート 8080 がすでに使われている場合**
>
> compose ファイルを編集する代わりに、`docker-compose.yml` と同じ場所にある `.env` ファイルで別のホストポートを選んでください。
>
> ```
> printf '\nCASHPILOT_UI_PORT=8088\n' >> .env
> docker compose up -d
> ```
>
> その後、http://localhost:8088 を開きます。値は `.env` に残しておいてください。 アプリ内の更新はシェルではなくこのファイルを読むからです。(`printf` が 改行から始まるのは、既存の `.env` の最後の行とつながらないようにするためです。)
>
> この変数を使うには、`ports:` の行が `${CASHPILOT_UI_PORT:-8080}:8080` となっている `docker-compose.yml` が必要です。v1.61 以前のファイルは `8080:8080` を固定で書いており、この変数を無視します。最新のファイルをダウンロードするか、 自分で編集したポートの対応付けをそのまま使ってください。アプリ内の更新はそれも受け入れます。

> [!WARNING]
>
> **初回起動時のセットアップトークンが必要です**
>
> 初回起動時に、CashPilot は 1 回限りのセットアップトークンを生成し、**cashpilot-ui** コンテナのログに出力します。
>
> ```
> docker compose logs cashpilot-ui
> ```
>
> 次のような行を探してください。
>
> ```
> FIRST-RUN SETUP: no account exists yet. Open /register and enter this
> one-time setup token to create the owner account: <token>
> ```
>
> ウェルカムページの **Owner account** (オーナーアカウント)ステップにある **Setup token** (セットアップトークン)欄にこのトークンをコピーし、ユーザー名とパスワードも入力して、最初の(オーナーの)アカウントを作成します。トークンはログにだけ表示され、URL に出ることはありません。オーナーアカウントができた時点で完全に破棄されます。

### 3\. サービスカタログを見る

**Catalog** (カタログ)ページには、すべてのサービスが、対応プラットフォーム、月ごとの見込み額、必要なもの(住宅用 IP、GPU)とともに表示されます。カテゴリー(帯域、DePIN、ストレージ、コンピュート、マイニング)で絞り込むか、名前で検索してください。**Add** (追加)はそのサービスでセットアップウィザードを開き、**Details** (詳細)はその説明、支払い、デプロイのリスクを表示します。Docker で動かないサービスには、代わりに **Visit** (開く)リンクがあります。

2 種類のサービスは、先によく確認してください。トークンをステークとしてロックしないと支払われないサービス(Anyone Protocol、Sia、Flux など)と、あなたの IP を公開するリレーです。後者は、住宅用の帯域アプリから受け取る額を下げることがあります。[デプロイ前に確認する 2 つのこと](<https://geiserx.github.io/CashPilot/ja/guides/index.md>)を参照してください。

### 4\. ウィザードでサービスを追加する

オーナーアカウントができると、**Add services** (サービスを追加)でセットアップウィザードが開きます。その後は、上部バーの **\+ Add service** (+ サービスを追加)ボタンでもう一度開けます。カテゴリーを選び、次にサービスを選びます。ウィザードはサービスごとに **Sign Up** (登録)リンクを表示し、そのサービスに必要な認証情報だけ(メールアドレスとパスワード、API トークンなど)を尋ね、それを動かすワーカーを選ばせます。**Deploy** (デプロイ)をクリックすると、CashPilot がイメージを取得し、コンテナを作成して監視を始めます。

### 5\. ダッシュボードで確認する

ダッシュボードには、デプロイした各サービスが状態と残高とともに表示されます。**Fleet** (フリート)ページにはすべてのワーカーが表示されます。

## 仕組み

```
graph LR
    A[User] -->|Browse & Configure| B[CashPilot UI<br>Port 8080]
    B -->|Deploy Commands| C[CashPilot Worker<br>Port 8081]
    C -->|Docker API| D[Service Containers]
    D -->|Health & Status| C
    C -->|Heartbeat| B
    B -->|Collect Earnings| E[Service APIs]
    E -->|Balance Data| B
```

1. **あなたが** Web UI でサービスを設定します。サービスを選び、認証情報を入力し、デプロイをクリックします。
2. **UI が** コンテナの仕様(イメージ、環境変数、ボリューム)を REST API でワーカーに送ります。
3. **ワーカーが** Docker コンテナを作成し、その正常性の監視を始めます。
4. **ワーカーが** 60 秒ごとにハートビートでコンテナの状態を UI に報告します。
5. **UI が** 設定可能なスケジュール(既定は 1 時間ごと)でサービスの API から収益を収集します。
6. **ダッシュボードが** 合計の収益、サービスごとの内訳、コンテナの正常性を表示します。

## 設定

### UI の環境変数

| 変数 | 既定値 | 説明 |
| --- | --- | --- |
| `TZ` | `UTC` | スケジュールと表示に使うタイムゾーン |
| `CASHPILOT_SECRET_KEY` | *(自動生成)* | ログインセッションの署名鍵。`/data/.secret_key` に保存されます。**認証情報は暗号化しません** |
| `CASHPILOT_ENCRYPTION_KEY` | *(自動生成)* | 保存された認証情報を暗号化する Fernet 鍵。`/data/.fernet_key` に保存されます。そのファイルがないときだけ使われ、`/data` に書き込まれることはありません。`CASHPILOT_ENCRYPTION_KEY_FILE`(パス)はその両方より優先されます。[データフォルダーの外に置く暗号化キー](<https://geiserx.github.io/CashPilot/ja/encryption-key/index.md>)を参照してください |
| `CASHPILOT_API_KEY` | *(`/fleet` から)* | ワーカー共通の参加用キー。各ワーカーは参加時に自分専用のキーを受け取ります。[フリート](<https://geiserx.github.io/CashPilot/ja/fleet/index.md>)を参照してください |
| `CASHPILOT_COLLECT_INTERVAL` | `60` | 収益収集サイクルの間隔(分) |
| `CASHPILOT_UI_PORT` | `8080` | UI を公開するホストポート。8080 が使用中のときは `.env` で設定します |
| `CASHPILOT_BIND_ADDR` | `127.0.0.1` | UI のポートを公開するホストのインターフェース。**既定はループバックです**。ダッシュボードは Docker ソケットを持つワーカーに命令できるため、初期状態ではネットワークに公開されません。公開するには特定の IP(Tailscale や VPN のアドレスなど)か `0.0.0.0` を設定するか、(推奨)認証付きのリバースプロキシを前に置いてください |

コンテナ内の UI の Web ポートは `8080` で固定です(コンテナの `CMD` で設定)。`CASHPILOT_UI_PORT` と `CASHPILOT_BIND_ADDR` が選ぶのは、公開先のホストポートとインターフェースだけです。

### ワーカーの環境変数

| 変数 | 既定値 | 説明 |
| --- | --- | --- |
| `TZ` | `UTC` | タイムゾーン |
| `CASHPILOT_UI_URL` | \-- | UI コンテナの URL。例: `http://cashpilot-ui:8080` |
| `CASHPILOT_API_KEY` | \-- | UI の参加用キーと一致する必要があります。必要なのは参加時だけで、その後ワーカーは自分専用のキーを使います |
| `CASHPILOT_WORKER_NAME` | *(ホスト名)* | フリートのダッシュボードに表示されるこのワーカーの名前 |
| `CASHPILOT_WORKER_URL` | *(自動検出)* | UI がこのワーカーに接続するための URL。例: `http://192.168.1.50:8081`。ホストをまたぐフリートでは明示的に設定してください。自動検出では、到達できないコンテナ内部の IP が報告されることがあります |
| `CASHPILOT_WORKER_BIND_ADDR` | `127.0.0.1` | **フリートとリモートワーカーの compose のみ**(`docker-compose.fleet.yml`): ワーカーの Docker ソケット API ポートを公開するホストのインターフェース。既定はループバックです。既定の `docker-compose.yml` はポート 8081 をまったく公開しません。ワーカー API は任意のコンテナをデプロイ・停止できる(= ホストの root 権限)ため、リモートワーカーではプライベートまたは VPN のインターフェース(Tailscale の IP など)にバインドし、パブリック IP には**絶対に**バインドしないでください |
| `CASHPILOT_PORT` | `8081` | ワーカーが UI に**通知する**ポート。待ち受けポートは変わり*ません*。待ち受けポートはイメージの `CMD` で固定されています。[設定リファレンス](<https://geiserx.github.io/CashPilot/ja/configuration/index.md>)を参照してください |

### Docker Compose の例

```
# CashPilot - Self-hosted passive income orchestrator
# https://github.com/GeiserX/CashPilot
#
# UI + Worker on the same server. For multi-server fleet, see docker-compose.fleet.yml
#
#   Start / update:  docker compose pull && docker compose up -d
#
# ONE CashPilot per Docker host. The container names in this file are fixed,
# and a worker manages every container on its Docker engine that carries
# CashPilot's labels, whichever install made it. A second install on the same
# host would list, stop and replace the first one's earners. Put it on another
# host or VM. docs/getting-started.md has the details.
#
# Images are PINNED to a major.minor tag, which is what the lines below say.
# `docker compose pull && up -d` therefore gets the newest patch of that series,
# not the newest release overall. To move to a newer series, read UPGRADING.md
# first, then edit the tags on the UI host first and on every worker after it.
#
# This header used to claim the file tracked `latest` while pinning 1.4, and the
# string `:latest` it told you to replace did not appear anywhere. Following the
# quickstart therefore installed a version many releases behind, and issue #188
# is someone hitting a first-run bug that had been fixed for months because of
# it. Keep this comment honest about what the file actually does.
# See https://hub.docker.com/r/drumsergio/cashpilot/tags for available tags.
# NOTE: versions before 1.0.0 predate the per-worker fleet-key auth cutover and
# are not compatible with a worker running 1.x -- pin UI and worker together.
# Building from source? Use: docker compose -f docker-compose.build.yml up -d

services:
  cashpilot-ui:
    image: drumsergio/cashpilot:3.3
    pull_policy: always
    container_name: cashpilot-ui
    # Published on loopback by default: the dashboard can command the Docker-socket
    # worker, so it must not be exposed to your LAN/the internet out of the box.
    # To reach it from another machine, point CASHPILOT_BIND_ADDR at a specific
    # interface (e.g. a Tailscale/VPN IP) or, better, run an authenticating reverse
    # proxy in front. CASHPILOT_BIND_ADDR=0.0.0.0 publishes on all interfaces.
    # Host port 8080 already taken? Set CASHPILOT_UI_PORT=8088 (and CASHPILOT_BIND_ADDR)
    # in a .env file next to this compose file, not on the command line. The in-app
    # update reads .env and never sees your shell. The container port stays 8080.
    ports:
      - "${CASHPILOT_BIND_ADDR:-127.0.0.1}:${CASHPILOT_UI_PORT:-8080}:8080"
    volumes:
      - cashpilot_data:/data
      - cashpilot_fleet_owned:/fleet
    environment:
      - TZ=${TZ:-UTC}
      - CASHPILOT_SECRET_KEY=${CASHPILOT_SECRET_KEY:-}
      # Optional: only needed to RESTORE credentials onto a fresh volume.
      # An existing /data/.fernet_key always wins, so setting this is safe.
      - CASHPILOT_ENCRYPTION_KEY=${CASHPILOT_ENCRYPTION_KEY:-}
      - CASHPILOT_ALLOW_EPHEMERAL_KEY=${CASHPILOT_ALLOW_EPHEMERAL_KEY:-false}
      - CASHPILOT_API_KEY=${CASHPILOT_API_KEY:-}
      - CASHPILOT_ADMIN_API_KEY=${CASHPILOT_ADMIN_API_KEY:-}
      # Optional bearer key for reporting only (Home Assistant, Grafana,
      # cashpilot-mcp with CASHPILOT_READ_ONLY=true). See docs/configuration.md.
      - CASHPILOT_READONLY_API_KEY=${CASHPILOT_READONLY_API_KEY:-}
      # Optional Prometheus /metrics. true serves it; set a token to require
      # Authorization: Bearer. See docs/guides/prometheus-metrics.md.
      - CASHPILOT_METRICS_ENABLED=${CASHPILOT_METRICS_ENABLED:-false}
      - CASHPILOT_METRICS_TOKEN=${CASHPILOT_METRICS_TOKEN:-}
      # Optional CAPTCHA on the sign-in page, for a UI the internet can reach:
      # turnstile, hcaptcha or recaptcha (v2 checkbox), plus both keys. Empty = off.
      # See docs/security-defaults.md, "Protect the sign-in page with a CAPTCHA".
      - CASHPILOT_CAPTCHA_PROVIDER=${CASHPILOT_CAPTCHA_PROVIDER:-}
      - CASHPILOT_CAPTCHA_SITE_KEY=${CASHPILOT_CAPTCHA_SITE_KEY:-}
      - CASHPILOT_CAPTCHA_SECRET_KEY=${CASHPILOT_CAPTCHA_SECRET_KEY:-}
      # Warn when a container misses a later catalog fix. false turns it off.
      - CASHPILOT_DRIFT_WARNINGS=${CASHPILOT_DRIFT_WARNINGS:-true}
    init: true
    # The image declares its own HEALTHCHECK, so `docker ps` will show
    # "(unhealthy)" when the app stops answering. NOTHING ACTS ON THAT BY
    # DEFAULT: `restart: unless-stopped` restarts a container that EXITS, and a
    # container failing its healthcheck is still running. It will sit there
    # unhealthy indefinitely. (Docker Swarm reschedules unhealthy tasks; plain
    # Compose does not.)
    #
    # To act on it, either alert on it -- see the CashPilotDown rule in
    # docs/guides/prometheus-metrics.md -- or add an autoheal sidecar, which is
    # documented in the same place along with the fact that it needs the Docker
    # socket, i.e. root on the host.
    restart: unless-stopped
    security_opt:
      - no-new-privileges:true
    tmpfs:
      - /tmp:size=64M
    # cashpilot_fleet_owned is filled by cashpilot-migrate on an upgrade.
    depends_on:
      cashpilot-migrate:
        condition: service_completed_successfully
    # Where the UI reaches the worker. Labelled for the proxy, so the in-app
    # update may attach the worker to it.
    networks:
      - cashpilot_owned

  # Runs once at every `docker compose up`, before the proxy, and exits.
  # Releases before owner isolation made volumes and the LAN fence's network
  # without the proxy's owner label, and Docker cannot add a label later, so
  # this copies each one to a backup, recreates it with the label, copies the
  # data back and checks it, then recreates the service container as it was.
  # The backups (<volume>-pre-isolation) and the volumes this file renamed are
  # never deleted: UPGRADING.md says how to remove them. It holds the raw
  # socket only while it runs; a second run finds nothing to do.
  cashpilot-migrate:
    image: drumsergio/cashpilot-worker:3.3
    pull_policy: always
    container_name: cashpilot-migrate
    user: "0:0"
    entrypoint: ["python", "-m", "app.owner_migrate"]
    environment:
      # old=new compose volume keys: the data moves into the labelled volume.
      - CASHPILOT_MIGRATE_COMPOSE_VOLUMES=cashpilot_worker_data=cashpilot_worker_data_owned,cashpilot_fleet=cashpilot_fleet_owned
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      # Each step it finished, so a run killed halfway is completed by the next.
      # A folder, not a volume: the in-app update runs docker compose through
      # the proxy, and Compose checks every volume of the worker's dependencies,
      # this one included, which the proxy will not let the worker see.
      - ./cashpilot-migrate-state:/state
    network_mode: none
    restart: "no"
    healthcheck:
      disable: true
    cap_drop:
      - ALL
    security_opt:
      - no-new-privileges:true

  # Holds the host's Docker socket so the worker does not have to. It serves
  # a filtered copy in the cashpilot_docker_api volume and refuses every call
  # the worker does not make: a privileged container, a bind of / or of the
  # socket, a capability or device outside the catalog's, exec of anything but
  # the catalog's readers, swarm, plugins, builds. The policy is the configs
  # block at the end of this file. docs/security-defaults.md has the details.
  #
  # Pinned by digest and bumped on purpose; the in-app update never recreates
  # it (it runs `up --no-deps` on the UI and worker only).
  cashpilot-socket-proxy:
    image: codeswhat/sockguard:2.4.10@sha256:af66f6dcab2d6c04c4a45823ea9b72549985bf1957dea3bb4382c1515ab9461e
    container_name: cashpilot-socket-proxy
    # Root with no capabilities: uid 0 opens the root-owned host socket, and
    # group 1000 (the worker's) lets it give the worker its socket.
    user: "0:0"
    group_add:
      - "1000"
    cap_drop:
      - ALL
    # One capability it never uses, and that no container the worker creates
    # may ask for. A container that joins this one's process namespace then
    # holds less than the proxy does, so the kernel refuses it the proxy's
    # files (/proc/1/root), the host socket among them.
    cap_add:
      - WAKE_ALARM
    security_opt:
      - no-new-privileges:true
    # Unix sockets only; it needs no network at all.
    network_mode: none
    restart: unless-stopped
    # It peaks near 45 MB, streams included; the cap only stops a leak
    # from taking the host's memory with it.
    mem_limit: 256m
    # One log line per Docker call (refusals included), so the log is capped.
    logging:
      driver: json-file
      options:
        max-size: "5m"
        max-file: "2"
    # `sockguard verify` asks the host's Docker through the socket this proxy
    # holds, so a stale or missing host socket (a Docker update replaced it,
    # docs/faq.md) turns it unhealthy. Exec form: the image has no shell.
    healthcheck:
      test: ["CMD", "/sockguard", "verify"]
      interval: 60s
      timeout: 10s
      retries: 3
      start_period: 20s
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - cashpilot_docker_api:/run/cashpilot-docker
    environment:
      # Host paths containers may bind: your compose folder (the in-app
      # update needs it) and each folder a service keeps its data in (Storj's
      # identity and data folders, for example), comma-separated. Set both in
      # the .env next to this file. The proxy binds a listed path only as
      # itself, never a folder under it, so list every path a service binds.
      # Write each as an exact absolute path, with no trailing slash, `//`, `.`
      # or `..`: the proxy refuses to start on any other spelling.
      # The placeholders sit under /dev/null, where no directory can ever exist
      # (Docker cannot create one there), so an unset variable allows nothing.
      - SOCKGUARD_REQUEST_BODY_CONTAINER_CREATE_ALLOWED_BIND_MOUNTS=${CASHPILOT_COMPOSE_DIR:-/dev/null/cashpilot-compose-dir-unset},${CASHPILOT_PROXY_BIND_MOUNTS:-/dev/null/cashpilot-bind-mounts-unset}
      # The policy's fingerprint. Compose does not recreate a container when
      # only its config's content changes, so this line is what makes
      # `docker compose up -d` restart the proxy on a new policy.
      - CASHPILOT_PROXY_POLICY=bf36af85a1e0f393
    configs:
      - source: cashpilot_socket_policy
        target: /etc/sockguard/sockguard.yaml
    depends_on:
      cashpilot-migrate:
        condition: service_completed_successfully

  cashpilot-worker:
    image: drumsergio/cashpilot-worker:3.3
    pull_policy: always
    container_name: cashpilot-worker
    # The proxy's owner label: the worker may read its own container, and the
    # in-app update may recreate it through the proxy.
    labels:
      cashpilot.deployed-by: worker
    expose:
      - "8081"
      # The worker reads host GPU information from sysfs. Leave the GPU
      # devices on the host so it can grant them to catalog services
      # that declare docker.gpu. See docs/gpu.md.
    volumes:
      # No Docker socket here: the worker reaches Docker through the proxy's
      # filtered socket in this volume (DOCKER_HOST below).
      - cashpilot_docker_api:/run/cashpilot-docker
      # SEPARATE FROM THE UI'S /data, DELIBERATELY. This container drives
      # Docker, so a flaw in it reaches the host. The UI's /data holds
      # cashpilot.db and .fernet_key -- the credential store and the only key
      # that can decrypt it -- and the component that can start any container
      # on the machine has no business being able to read them.
      #
      # /fleet IS shared on purpose: it holds only the shared enrolment key,
      # which both sides need by definition.
      #
      # Consolidating these into one volume is the obvious "simplification" and
      # it silently removes that boundary. tests/test_beads_batch_69.py fails if
      # anyone does.
      - cashpilot_worker_data_owned:/data
      - cashpilot_fleet_owned:/fleet
    environment:
      - TZ=${TZ:-UTC}
      - CASHPILOT_UI_URL=http://cashpilot-ui:8080
      - CASHPILOT_API_KEY=${CASHPILOT_API_KEY:-}
      - CASHPILOT_WORKER_NAME=local
      - CASHPILOT_MINERS=${CASHPILOT_MINERS:-}
      - DOCKER_HOST=unix:///run/cashpilot-docker/docker.sock
      # The proxy policy's fingerprint (scripts/socket_proxy_policy.py), so the
      # worker can say when its image needs a newer policy than this file has.
      - CASHPILOT_PROXY_POLICY=bf36af85a1e0f393
      # The same two values the proxy gets, so the worker can say what to set
      # before the proxy refuses (the in-app update, a host-folder bind).
      - CASHPILOT_COMPOSE_DIR=${CASHPILOT_COMPOSE_DIR:-}
      - CASHPILOT_PROXY_BIND_MOUNTS=${CASHPILOT_PROXY_BIND_MOUNTS:-}
      # Earners are fenced off your LAN and this host by default (docs/isolation.md).
      # off keeps Docker's default bridge.
      - CASHPILOT_ISOLATION=${CASHPILOT_ISOLATION:-auto}
      - CASHPILOT_DRIFT_WARNINGS=${CASHPILOT_DRIFT_WARNINGS:-true}
    depends_on:
      - cashpilot-socket-proxy
    init: true
    restart: unless-stopped
    security_opt:
      - no-new-privileges:true
    tmpfs:
      - /tmp:size=64M
    # Labelled for the proxy, so the in-app update may attach the worker to it.
    networks:
      - cashpilot_owned

volumes:
  cashpilot_data:
  # The worker's own data and the enrolment key it shares with the UI. They
  # carry the proxy's owner label, so the in-app update may mount them. Compose
  # never relabels a volume, so they are new ones: cashpilot-migrate copied
  # cashpilot_worker_data and cashpilot_fleet into them and left the old ones
  # as backups. The UI's cashpilot_data never carries the label.
  cashpilot_worker_data_owned:
    labels:
      cashpilot.deployed-by: worker
  cashpilot_fleet_owned:
    labels:
      cashpilot.deployed-by: worker
  # Fixed name: the in-app update mounts it by name to reach the proxy. It
  # replaced cashpilot-docker-api, which held nothing but the socket.
  cashpilot_docker_api:
    name: cashpilot-docker-api-owned
    labels:
      cashpilot.deployed-by: worker

networks:
  cashpilot_owned:
    labels:
      cashpilot.deployed-by: worker

# The Docker socket proxy's policy. scripts/socket_proxy_policy.py writes it
# from the catalog; `$$` is how compose spells a literal `$`. Needs Docker
# Compose 2.23.1 or newer (inline config content).
configs:
  cashpilot_socket_policy:
    content: |
      # BEGIN socket proxy policy: written by scripts/socket_proxy_policy.py, do not edit by hand
      listen:
        socket: /run/cashpilot-docker/docker.sock
        # The worker runs as uid/gid 1000 (Dockerfile.worker). The proxy runs as
        # root with no capabilities and joins group 1000, so it can hand the socket
        # to that group without asking for the host's docker group id.
        socket_mode: "0660"
        socket_gid: 1000
      upstream:
        socket: /var/run/docker.sock
        # Image pulls and container waits take minutes; the default cuts them at 60 s.
        request_timeout: "off"
      log:
        level: info
        format: json
        # One line per call, refusals included: docker logs cashpilot-socket-proxy
        # shows what was refused and why. The compose file caps the log's size.
        access_log: true
      health:
        enabled: false
      # The worker reads its own containers' logs and files (backups, the update check).
      insecure_allow_read_exfiltration: true
      response:
        # A refusal carries the rule's reason, which the worker shows to you.
        deny_verbosity: verbose
        # The worker reads Env, Mounts and IPAM back (recreates, the isolation check).
        redact_container_env: false
        redact_mount_paths: false
        redact_network_topology: false
      request_body:
        container_create:
          allow_privileged: false
          # The LAN fence helper and the isolation check's control probe run on the
          # host network; no earner does (the worker refuses it for every catalog
          # service, and the catalog refuses it to any service with NET_ADMIN).
          allow_host_network: true
          allow_host_pid: false
          allow_host_ipc: false
          allow_host_userns: false
          allow_host_cgroupns: false
          allowed_capabilities: [NET_ADMIN, NET_RAW, SETUID, SETGID]
          allowed_devices: [/dev/net/tun, /dev/dri/renderD128, /dev/dri/renderD129, /dev/dri/renderD130, /dev/dri/renderD131, /dev/dri/renderD132, /dev/dri/renderD133, /dev/dri/renderD134, /dev/dri/renderD135, /dev/kfd, /dev/ttyUSB0, /dev/ttyUSB1, /dev/ttyUSB2, /dev/ttyUSB3, /dev/ttyUSB4, /dev/ttyUSB5, /dev/ttyUSB6, /dev/ttyUSB7, /dev/ttyUSB8, /dev/ttyUSB9, /dev/ttyACM0, /dev/ttyACM1, /dev/ttyACM2, /dev/ttyACM3, /dev/ttyACM4, /dev/ttyACM5, /dev/ttyACM6, /dev/ttyACM7, /dev/ttyACM8, /dev/ttyACM9]
          allowed_device_requests: [{driver: nvidia, allowed_capabilities: [[gpu]]}]
          allowed_runtimes: [runc, runsc, runsc-hostnet, runsc-hostnet-raw]
          allow_sysctls: true               # the tunnel sidecar turns IPv6 off in its own namespace
          require_no_new_privileges: true
          deny_unconfined_seccomp: true
          deny_unconfined_apparmor: true
          deny_unconfined_system_paths: true
          # Host folders containers may bind come from CASHPILOT_COMPOSE_DIR and
          # CASHPILOT_PROXY_BIND_MOUNTS, through the proxy service's environment.
          allowed_bind_mounts: []
        container_remove:
          allow_force: true
          allow_remove_volumes: true
        container_archive:
          # The only folder the worker writes into a container: the tunnel
          # sidecar's proxy settings.
          allowed_paths: [/run/cashpilot-secret]
          allow_setid: false
          allow_device_nodes: false
          allow_escaping_links: false
        exec:
          allow_privileged: false
          allow_root_user: true
          # The worker's exec calls send no environment. This name is never sent,
          # so any Env entry (PATH, LD_PRELOAD) is refused.
          allowed_env_vars: [CASHPILOT_EXEC_SENDS_NO_ENV]
          allowed_commands:
            - ["cat", "/run/ready"]
            - ["sh", "-c", "id=$$(wget -qO- -T 5 http://127.0.0.1:4050/identities | grep -o '0x[0-9a-fA-F]\\{40\\}' | head -1) && wget -qO- -T 5 \"http://127.0.0.1:4050/identities/$$id\" && { echo; wget -qO- -T 5 \"http://127.0.0.1:4050/transactor/settle/history?page_size=1000\" || true; }"]
            - ["sh", "-c", "id=$$(wget -qO- -T 5 http://127.0.0.1:4050/identities | grep -o '0x[0-9a-fA-F]\\{40\\}' | head -1) && wget -qO- -T 5 \"http://127.0.0.1:4050/identities/$$id/beneficiary\""]
            - ["timeout", "12", "sh", "-c", "if m=$$(wget -qO- -Y off -T 5 http://127.0.0.1:4050/node/monitoring-status); then\n  echo \"monitoring read: $$m\"\nfi\nset -o pipefail\nif s=$$(wget -qO- -Y off -T 5 \"http://127.0.0.1:4050/sessions?direction=Provided&status=Completed&page_size=100\") &&\n  sorted=$$(echo \"$$s\" | sed 's/},{/}\\n{/g' | awk '\n    match($$0, /\"created_at\":\"[^\"]+\"/) {\n      t = substr($$0, RSTART + 14, 19); gsub(/[-T:]/, \" \", t)\n      d = 0; if (match($$0, /\"duration\":[0-9]+/)) d = substr($$0, RSTART + 11, RLENGTH - 11)\n      print mktime(t) + d, $$0\n    }' | sort -rn); then\n  [ -z \"$$sorted\" ] || echo \"$$sorted\" | head -5\n  echo \"sessions read: all\"\nfi"]
            - ["sh", "-c", "T=\"\"; command -v timeout >/dev/null 2>&1 && T=\"timeout 5\"; $$T iptables-nft -t nat -S MYST 2>/dev/null; if grep -qx nat /proc/net/ip_tables_names 2>/dev/null; then $$T iptables-legacy -t nat -S MYST 2>/dev/null; $$T iptables -t nat -S MYST 2>/dev/null; else case \"$$($$T iptables -V 2>/dev/null)\" in *nf_tables*) $$T iptables -t nat -S MYST 2>/dev/null;; esac; fi"]
            - ["cat", "/etc/anon/anonrc"]
        image_pull:
          allow_all_registries: true        # catalog and custom services come from many registries
        network:
          # The LAN fence (app/lan_fence.py) creates its bridge with three driver
          # options (interface name, no masquerade, no inter-container traffic) and
          # moves an earner across with a forced disconnect. Custom drivers, swarm
          # scope, custom IPAM and endpoint settings stay refused.
          allow_driver_options: true
          allow_disconnect_force: true
        volume:
          # Plain local volumes only: driver options could point one at a host folder.
          allow_custom_drivers: false
          allow_driver_opts: false
      # The worker sees and touches only what carries the owner label below: what
      # it created through this proxy, and what app/owner_migrate.py labelled. The
      # UI's container and its data volume never carry it.
      ownership:
        owner: worker
        label_key: cashpilot.deployed-by
        # Images carry no owner: one pulled for an earner is shared with the host.
        allow_unowned_images: true
        allow_cross_owner_namespace_sharing: false
      rules:
        - {match: {method: GET, path: "/_ping"}, action: allow}
        - {match: {method: HEAD, path: "/_ping"}, action: allow}
        - {match: {method: GET, path: "/version"}, action: allow}
        - {match: {method: GET, path: "/info"}, action: allow}
        - {match: {method: GET, path: "/containers/json"}, action: allow}
        - {match: {method: GET, path: "/containers/*/json"}, action: allow}
        - {match: {method: POST, path: "/containers/create"}, action: allow}
        - {match: {method: POST, path: "/containers/*/start"}, action: allow}
        - {match: {method: POST, path: "/containers/*/stop"}, action: allow}
        - {match: {method: POST, path: "/containers/*/restart"}, action: allow}
        - {match: {method: POST, path: "/containers/*/pause"}, action: allow}
        - {match: {method: POST, path: "/containers/*/unpause"}, action: allow}
        - {match: {method: POST, path: "/containers/*/wait"}, action: allow}
        - {match: {method: POST, path: "/containers/*/rename"}, action: allow}
        - {match: {method: DELETE, path: "/containers/*"}, action: allow}
        - {match: {method: GET, path: "/containers/*/logs"}, action: allow}
        - {match: {method: GET, path: "/containers/*/stats"}, action: allow}
        - {match: {method: GET, path: "/containers/*/archive"}, action: allow}
        - {match: {method: PUT, path: "/containers/*/archive"}, action: allow}
        - {match: {method: POST, path: "/containers/*/exec"}, action: allow}
        - {match: {method: POST, path: "/exec/*/start"}, action: allow}
        - {match: {method: GET, path: "/exec/*/json"}, action: allow}
        - {match: {method: GET, path: "/images/**/json"}, action: allow}
        - {match: {method: POST, path: "/images/create"}, action: allow}
        - {match: {method: GET, path: "/networks"}, action: allow}
        - {match: {method: GET, path: "/networks/*"}, action: allow}
        - {match: {method: POST, path: "/networks/create"}, action: allow}
        - {match: {method: POST, path: "/networks/*/connect"}, action: allow}
        - {match: {method: POST, path: "/networks/*/disconnect"}, action: allow}
        - {match: {method: DELETE, path: "/networks/*"}, action: allow}
        - {match: {method: POST, path: "/volumes/create"}, action: allow}
        - {match: {method: GET, path: "/volumes/*"}, action: allow}
        - {match: {method: DELETE, path: "/volumes/*"}, action: allow}
        - {match: {method: "*", path: "/**"}, action: deny, reason: "the CashPilot worker does not use this Docker API call"}
      # END socket proxy policy
```

> [!NOTE]
>
> **これが実際のファイルです**
>
> 上のブロックはリポジトリの `docker-compose.yml` をそのまま取り込んでいるので、 実際に配布されるものとずれることはありません。以前は手でコピーした版があり、 ワーカーの Docker ソケット API をすべてのインターフェースで公開し、`:latest` を指定していました。 どちらも[セキュリティの既定値](<https://geiserx.github.io/CashPilot/ja/security-defaults/index.md>)のページでやめるよう求めていることです。

> [!WARNING]
>
> **Docker ソケットへのアクセス**
>
> ワーカーは Docker を通じてサービスのコンテナを管理しますが、`/var/run/docker.sock` はマウントしません。`cashpilot-socket-proxy` コンテナがソケットを保持し、ワーカーが行う呼び出しだけを通します。特権コンテナと、あなたが指定していないホストのフォルダーのバインドは拒否します([何を拒否するか](<https://geiserx.github.io/CashPilot/ja/security-defaults/index.md#docker-socket-proxy>))。アプリ内の更新はオプトインです。compose ファイルと同じ場所の `.env` に `CASHPILOT_COMPOSE_DIR=<this folder>` があるときだけ動きます。この設定によりコンテナがそのフォルダーをバインドできるようになり、プロキシの保護が弱まります([その代償](<https://geiserx.github.io/CashPilot/ja/security-defaults/index.md#docker-socket-proxy>))。設定しないままにして、`docker compose pull && docker compose up -d` で更新してください。それでもワーカーはホスト上のすべてのコンテナを制御するので、セキュリティを最大にするには CashPilot を専用のマシンか VLAN で動かしてください。

> [!TIP]
>
> **シークレットキーの保持**
>
> 認証情報は `CASHPILOT_ENCRYPTION_KEY` で暗号化されます。`CASHPILOT_SECRET_KEY` では**ありません**。こちらはログインセッションに署名するだけです。暗号化キーは初回起動時に自動生成され、`/data/.fernet_key` に保存されます。**このファイルをバックアップしてください。** ボリュームをこのファイルなしで作り直すと、新しいキーが生成され、保存済みのすべての認証情報が永久に読めなくなります。`CASHPILOT_ENCRYPTION_KEY` を設定するのは、そのバックアップを復元するためです。キーファイルが常に優先されるので、正常なインスタンスで設定しても何も変わりません。

> [!TIP]
>
> **UI でのパスワードとシークレット**
>
> 自分のパスワードは、アバターメニュー -\> **Change password** (パスワードを変更)からいつでも変更できます(すべてのロールで利用可能)。変更すると、ほかのセッションはサインアウトされます。**Settings** (設定)では、保存済みのシークレットは書き込み専用です。変更するには値を入力し、今の値を残すには欄を空のままにします。保存された認証情報がブラウザーに送り返されることはありません。

## CashPilot の更新

compose ファイルは `drumsergio/cashpilot:X.Y` のようにメジャー.マイナーのシリーズを固定しているので、`pull` はそのシリーズの最新パッチを取得します。

```
docker compose pull
docker compose up -d
```

`docker compose pull` は公開されている最新のイメージを取得し、`up -d` は イメージが変わったコンテナだけを作り直します。配布している compose ファイルは `pull_policy: always` を設定しているので、`docker compose up -d` だけでも 先に最新のイメージを取得します。

**ダッシュボードから。** **Settings** (設定)の **About and updates** (情報と更新)は、 短時間だけ動くヘルパーコンテナから同じ 2 つのコマンドを実行します。ヘルパーが読むのは compose ファイルとその隣の `.env`(または `--env-file` で渡したファイル)で、 CashPilot を起動したシェルは読みません。たとえば `CASHPILOT_UI_PORT=8088 docker compose up -d` で起動したとします。 更新するとダッシュボードが 8080 に戻ってしまうので、更新は止まり、その理由を表示します。 その値を `.env` に書けば、ボタンは動きます。

> [!NOTE]
>
> **再ビルドは**必要ありません****
>
> CashPilot はビルド済みのマルチアーキテクチャのイメージを Docker Hub で配布しています ([`drumsergio/cashpilot`](<https://hub.docker.com/r/drumsergio/cashpilot>)、 [`drumsergio/cashpilot-worker`](<https://hub.docker.com/r/drumsergio/cashpilot-worker>))。 `docker compose build` / `--build` が関係するのは、`docker-compose.build.yml` を使って 意図的にソースからビルドする場合だけです。通常のインストールでは、 `pull` + `up -d` が完全で正しい更新手順です。

### 特定のバージョンに固定する

1 つのリリースにとどまるには、`docker-compose.yml` の `X.Y` シリーズのタグを、 `drumsergio/cashpilot` と `drumsergio/cashpilot-worker` の両方で完全なリリースタグ `X.Y.Z` に 置き換え(両方で必ず同じタグにします)、`pull_policy: always` を削除してください。タグは [Docker Hub](<https://hub.docker.com/r/drumsergio/cashpilot/tags>) で確認できます。

新しいシリーズに移るには、両方のタグを編集します。まず UI のホストで、次に すべてのワーカーのホストで行います。先に [UPGRADING.md](<https://github.com/GeiserX/CashPilot/blob/main/UPGRADING.md>) を読んでください。3.0 のようなメジャーリリースには独自の手順があるからです。

### 更新の自動化(任意)

手間をかけずに更新したい場合は、スケジューラーに同じ 2 つのコマンドを実行させます。 たとえば毎日の cron エントリーにします。

```
0 4 * * *  cd /path/to/cashpilot && docker compose pull && docker compose up -d
```

または、[Watchtower](<https://containrrr.dev/watchtower/>) や [Diun](<https://crazymax.dev/diun/>) などの自動更新ツールを CashPilot のコンテナに対して動かします。これらは 任意です。CashPilot には更新ツールは同梱されていません。

### 古いイメージの削除

CashPilot がイメージを削除するのは、[アプリのイメージ更新](<https://geiserx.github.io/CashPilot/ja/image-updates/index.md>)でそのイメージが置き換えられた後だけで、 それも生の Docker ソケットを持つワーカーでだけです。それ以外の場合、更新や再デプロイのたびに、 前のイメージがディスクに残ることがあります。3 台のサーバーのテスト用フリートでは、古い CashPilot と収益アプリのイメージは合計で約 3 GB でした。これは同じホストのほかのプログラムが ふつう残していく量に比べれば小さいので、ホスト全体を確認してください。

```
docker system df
```

`Images` の行の `RECLAIMABLE` の値が、Docker が解放できる量です。

**CashPilot がこれを代わりにやらない理由。** ワーカーはソケットプロキシを通じて Docker に 接続します。イメージについてプロキシが許可するのは、1 つを取得することと、1 つを名前で読むことだけです。 ホストのイメージを一覧表示することも、削除することもできません。それができるワーカーは、 ホスト上のほかのすべてのプログラムのイメージも見て削除できてしまいます。 [プロキシが拒否するもの](<https://geiserx.github.io/CashPilot/ja/security-defaults/index.md#docker-socket-proxy>)を参照してください。

**ステップ 1: ダングリングイメージを削除する。** ダングリングイメージとは、タグがなく、 実行中か停止中かを問わずどのコンテナも使っていないイメージです。`X.Y`(compose ファイルが固定しているようなシリーズ)、 `latest`、ダイジェストのような動くタグでの更新は、まさにこれを残します。

```
docker image prune
```

これは、動くタグで更新する前に使っていたイメージも削除します。そのシリーズの新しい イメージが届くと、古いものはタグを失うからです。戻れるようにしておくには、更新前に 正確なバージョンを控えておいてください(サイドバーの下部に表示されます)。そうすれば `drumsergio/cashpilot:<X.Y.Z>` をもう一度取得できます。または compose ファイルを 正確な `X.Y.Z` タグに固定します。その場合、古いイメージはタグを保ち、ステップ 2 が当てはまります。

Docker は削除する前に確認を求めます。cron エントリーでは `--force` を付けて確認を 省略してください。ほかには何も変わりません。

```
30 4 * * 0  docker image prune --force
```

> [!WARNING]
>
> **`-a` は付けないでください**
>
> `docker image prune -a` は、今どのコンテナも使っていないすべてのイメージを、 ダングリングでもタグ付きでも削除します。意図的に停止したスタックのイメージや、 ローカルでビルドして再取得できないイメージも含まれます。

**ステップ 2: 古い固定タグを削除する。** バージョンに固定したイメージは、新しいものに移った後も タグを保つので、`prune` はそれを飛ばします。次の CashPilot のイメージは固定されています。

| リポジトリ | 何が固定しているか |
| --- | --- |
| `drumsergio/cashpilot` | compose ファイル(古いシリーズ、または自分で固定した正確なバージョン) |
| `drumsergio/cashpilot-worker` | compose ファイル(上と同じ) |
| `drumsergio/cashpilot-tunnel` | ワーカー(ワーカーのバージョンごとに 1 つのタグ) |
| `drumsergio/cashpilot-earnapp` | EarnApp のカタログエントリー |
| `drumsergio/cashpilot-anyone` | Anyone Protocol のカタログエントリー |

削除したサービスのイメージも同じです。そのタグは、あなたが削除するまで残ります。 MystNodes や ProxyBase のようにダイジェストで固定されたカタログのイメージは、 新しいものに置き換わるとタグを失うので、ステップ 1 ですでに対処できます。

まず、どのコンテナも使っていないタグを一覧表示します。この例はワーカーのイメージ用です。 表のほかのリポジトリでは `repo` を変えてください。

```
repo=drumsergio/cashpilot-worker
used=$(docker ps -a --format '{{.Image}}')
docker image ls "$repo" --format '{{.Repository}}:{{.Tag}}' | grep -vxF "$used"
```

次に、古いタグを名前で 1 つずつ削除します。

```
docker image rm drumsergio/cashpilot-worker:<old tag>
```

`-f` は付けないでください。付けなければ、Docker は実行中か停止中かを問わずコンテナがまだ使っている イメージの削除を拒否し、`conflict: unable to delete` と表示します。これが出たら、そのイメージは 残してください。今使っているタグと、その前に使っていたタグは残し、1 つ前のバージョンに戻れるようにします。 削除するのは、その 2 つより古いタグだけにしてください。

ダッシュボードの **Host disk** (ホストのディスク)列には、ワーカーの `/data` があるファイルシステムの 空き容量が表示されます。イメージはふつう同じファイルシステムの Docker のデータルートの下にありますが、 いつもそうとは限りません。`docker info --format '{{.DockerRootDir}}'` で Docker のデータルートがわかります。新しい Docker Engine 29 のインストールで既定になっている containerd イメージストアでは、イメージは代わりに containerd のルートの下、ふつうは `/var/lib/containerd` にあります。`docker info --format '{{.Driver}}'` は、containerd イメージストアでは `overlayfs`、従来のものでは `overlay2` と表示します。 当てはまるディレクトリがあるファイルシステムの空き容量を確認してください。

## 対応サービス

CashPilot は、稼働中またはベータ版の **60 のサービス**に対応しています。カテゴリーは 5 つです。

- **帯域共有**(19): インターネットの帯域を共有して不労所得を得ます
- **DePIN**(16): 分散型物理インフラネットワーク
- **GPU コンピュート**(7): AI やコンピュートの処理向けに GPU を貸し出します
- **ストレージ**(3): 分散型ストレージネットワークでディスク容量を共有します
- **マイニング**(14): マイナーをデプロイするか、支払い先アドレスでプールを追跡します([マイニング](<https://geiserx.github.io/CashPilot/ja/mining/index.md>))

このうち **30** は、Docker で自動的にデプロイ・管理できます。残りの 30 はカタログで追跡します(ブラウザーまたはデスクトップのアプリが 19、GPU ノードが 7、マイニングプールが 4)。コレクターがあるものは、CashPilot がその残高を読み取ります。

カタログ全体は[サービスガイド](<https://geiserx.github.io/CashPilot/ja/guides/index.md>)のセクションで見られます。

## 次のステップ

- [仕組み](<https://geiserx.github.io/CashPilot/ja/how-it-works/index.md>) -- UI とワーカーに分けた設計を理解する
- [フリートの管理](<https://geiserx.github.io/CashPilot/ja/fleet/index.md>) -- 複数のサーバーにデプロイする
- [ホームネットワークを守る](<https://geiserx.github.io/CashPilot/ja/home-network-security/index.md>) -- コンテナを LAN から切り離す方法と、gVisor が役立つ場面
- [サービスガイド](<https://geiserx.github.io/CashPilot/ja/guides/index.md>) -- サービスごとの詳しいセットアップ手順
- [CashPilot を完全に削除する](<https://geiserx.github.io/CashPilot/ja/uninstall/index.md>) -- 作成されたものをすべて削除して、やり直すか使うのをやめる
