Bỏ qua
Chỉnh sửa

Bắt đầu

Bản tiếng Anh của trang này mới hơn. Đọc bản tiếng Anh.

Yêu cầu

  • Docker với plugin Compose v2, phiên bản 2.23.1 trở lên. Kiểm tra bằng docker compose version. Các phiên bản cũ hơn không đọc được cấu hình nội tuyến trong file compose. Docker Desktop đã có sẵn plugin này. Trên Docker Engine thuần trên Linux, hãy cài nó từ kho gói của Docker (https://docs.docker.com/compose/install/linux/). Trên macOS dùng Colima, hãy cài nó bằng Homebrew rồi liên kết nó thành plugin của 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
    
  • Một máy chủ Linux, macOS hoặc Windows (amd64 hoặc arm64)

  • Còn trống ít nhất 1 GB RAM cho CashPilot và các dịch vụ nó quản lý
  • Mỗi máy chủ Docker chỉ một CashPilot. Xem cảnh báo bên dưới.

Mỗi máy chủ Docker chỉ một CashPilot

Đừng chạy hai bản cài CashPilot trên cùng một máy chủ Docker. Các file compose dùng tên container cố định (cashpilot-ui, cashpilot-worker, cashpilot-socket-proxy), nên bản sao thứ hai của file sẽ lỗi vì trùng tên. Nếu bạn đổi tên để tránh lỗi đó, hai bản cài vẫn dùng chung máy chủ. Mỗi worker quản lý mọi container mang nhãn của CashPilot, bất kể bản cài nào đã tạo ra nó. Vì vậy mỗi bảng điều khiển sẽ liệt kê, dừng và thay thế các ứng dụng kiếm tiền của bản kia. Hai bản cài còn dùng chung mạng cashpilot-isolated, tên các ứng dụng kiếm tiền (cashpilot-<service>), cổng trên máy chủ và các volume như mysterium-data. Với bản cài thứ hai, hãy dùng một máy chủ hoặc VM khác. Để chạy ứng dụng kiếm tiền trên nhiều máy chủ hơn, hãy thêm worker vào một bảng điều khiển duy nhất (Đội máy).

Bắt đầu nhanh

1. Tải file compose và khởi chạy

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

Lệnh này khởi động ba container chạy lâu dài. Trước chúng, container chạy một lần cashpilot-migrate chạy và thoát với mã 0 ở mỗi lần up, nên docker compose ps -a hiển thị nó là Exited (0). Điều đó là bình thường.

Container Cổng Mục đích
cashpilot-migrate không có Chạy một lần rồi thoát. Nó chuyển dữ liệu mà một bản phát hành cũ đã tạo sang các volume mà socket proxy chấp nhận, và không có gì để làm trên bản cài mới
cashpilot-ui 8080 Bảng điều khiển web, thu thập thu nhập, danh mục dịch vụ
cashpilot-worker 8081 Agent Docker triển khai và giám sát container của các dịch vụ
cashpilot-socket-proxy không có Giữ Docker socket và đưa cho worker một bản đã lọc (Mặc định bảo mật)

2. Mở bảng điều khiển

Mở http://localhost:8080 trong trình duyệt. Vì chưa có tài khoản nào, bạn sẽ đến trang chào mừng, nơi tạo tài khoản chủ sở hữu.

Cổng 8080 đã bị dùng?

Chọn một cổng khác trên máy chủ trong file .env nằm cạnh docker-compose.yml, thay vì sửa file compose:

printf '\nCASHPILOT_UI_PORT=8088\n' >> .env
docker compose up -d

Sau đó mở http://localhost:8088. Hãy giữ giá trị này trong .env, vì bản cập nhật trong ứng dụng đọc file đó chứ không đọc shell của bạn. (printf bắt đầu bằng một ký tự xuống dòng để dòng mới không bao giờ dính vào dòng cuối của một .env đã có.)

Biến này cần một docker-compose.yml có dòng ports: là ${CASHPILOT_UI_PORT:-8080}:8080. File của v1.61 trở về trước ghi cứng 8080:8080 và bỏ qua biến này. Hãy tải file hiện tại, hoặc giữ ánh xạ cổng bạn đã tự sửa: bản cập nhật trong ứng dụng cũng chấp nhận cách đó.

Cần mã thiết lập cho lần chạy đầu

Ở lần khởi động đầu tiên, CashPilot tạo một mã thiết lập dùng một lần và in nó ra nhật ký của container cashpilot-ui:

docker compose logs cashpilot-ui

Tìm một dòng giống như:

FIRST-RUN SETUP: no account exists yet. Open /register and enter this
one-time setup token to create the owner account: <token>

Sao chép mã đó vào trường Setup token (Mã thiết lập) ở bước Owner account (Tài khoản chủ sở hữu) của trang chào mừng, cùng với tên người dùng và mật khẩu, để tạo tài khoản đầu tiên (chủ sở hữu). Mã này chỉ hiện trong nhật ký, không bao giờ trong URL, và bị hủy vĩnh viễn khi tài khoản chủ sở hữu đã tồn tại.

3. Xem danh mục dịch vụ

Trang Catalog (Danh mục) liệt kê mọi dịch vụ cùng các nền tảng, mức ước tính hằng tháng và những gì nó cần (IP dân cư, GPU). Lọc theo nhóm (Bandwidth (Băng thông), DePIN (DePIN), Storage (Lưu trữ), Compute (Điện toán), Mining (Đào coin)) hoặc tìm theo tên. Add (Thêm) mở trình hướng dẫn cài đặt cho dịch vụ đó, Details (Chi tiết) hiển thị mô tả, các khoản thanh toán và rủi ro khi triển khai, còn các dịch vụ không chạy trong Docker có liên kết Visit (Truy cập) thay thế.

Có hai loại dịch vụ cần xem kỹ trước: các dịch vụ chỉ trả tiền sau khi bạn khóa một khoản stake token, như Anyone Protocol, Sia và Flux, và các relay công khai IP của bạn, điều có thể làm giảm số tiền các ứng dụng băng thông dân cư trả cho bạn. Xem Kiểm tra hai điều trước khi triển khai.

4. Thêm dịch vụ bằng trình hướng dẫn

Khi tài khoản chủ sở hữu đã tồn tại, Add services (Thêm dịch vụ) mở trình hướng dẫn cài đặt; về sau, nút + Add service (+ Thêm dịch vụ) trên thanh trên cùng sẽ mở lại nó. Chọn các nhóm, rồi chọn dịch vụ. Với mỗi dịch vụ, trình hướng dẫn hiển thị một liên kết Sign Up (Đăng ký), chỉ hỏi những thông tin đăng nhập mà dịch vụ đó cần (email và mật khẩu, API token, v.v.) và cho bạn chọn các worker sẽ chạy nó. Nhấn Deploy (Triển khai) và CashPilot sẽ kéo image, tạo container và bắt đầu theo dõi nó.

5. Theo dõi trên bảng điều khiển

Bảng điều khiển hiển thị mỗi dịch vụ đã triển khai cùng trạng thái và số dư của nó, còn trang Fleet (Đội máy) hiển thị mọi worker.

Cách hoạt động

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. Bạn cấu hình dịch vụ qua giao diện web -- chọn một dịch vụ, nhập thông tin đăng nhập, nhấn triển khai.
  2. UI gửi đặc tả container (image, biến môi trường, volume) đến worker qua REST API.
  3. Worker tạo container Docker và bắt đầu giám sát sức khỏe của nó.
  4. Worker báo cáo trạng thái container về UI mỗi 60 giây bằng tín hiệu hoạt động.
  5. UI thu thập thu nhập từ API của các dịch vụ theo lịch có thể cấu hình (mặc định: mỗi giờ).
  6. Bảng điều khiển hiển thị tổng thu nhập, phần chia theo từng dịch vụ và sức khỏe container.

Cấu hình

Biến môi trường của UI

Biến Mặc định Mô tả
TZ UTC Múi giờ dùng cho lịch chạy và hiển thị
CASHPILOT_SECRET_KEY (tự tạo) Khóa ký cho các phiên đăng nhập. Lưu tại /data/.secret_key. Không mã hóa thông tin đăng nhập
CASHPILOT_ENCRYPTION_KEY (tự tạo) Khóa Fernet mã hóa thông tin đăng nhập được lưu trữ. Lưu tại /data/.fernet_key. Chỉ được dùng khi file đó không tồn tại, và không bao giờ được ghi vào /data. CASHPILOT_ENCRYPTION_KEY_FILE (một đường dẫn) được ưu tiên hơn cả hai: xem Khóa mã hóa bên ngoài thư mục dữ liệu
CASHPILOT_API_KEY (từ /fleet) Khóa ghi danh dùng chung cho các worker. Mỗi worker nhận khóa riêng khi ghi danh; xem Đội máy
CASHPILOT_COLLECT_INTERVAL 60 Số phút giữa các chu kỳ thu thập thu nhập
CASHPILOT_UI_PORT 8080 Cổng trên máy chủ mà UI được công bố. Đặt nó trong .env khi cổng 8080 đã bị dùng
CASHPILOT_BIND_ADDR 127.0.0.1 Giao diện mạng của máy chủ mà cổng UI được công bố. Mặc định là loopback: bảng điều khiển có thể ra lệnh cho worker có Docker socket, nên mặc định nó không lộ ra mạng của bạn. Đặt một IP cụ thể (ví dụ một địa chỉ Tailscale/VPN) hoặc 0.0.0.0 để công bố nó, hoặc (nên dùng) chạy một reverse proxy có xác thực ở phía trước

Cổng web của UI bên trong container cố định là 8080 (đặt qua CMD của container). CASHPILOT_UI_PORT và CASHPILOT_BIND_ADDR chỉ chọn cổng và giao diện mạng trên máy chủ mà nó được công bố.

Biến môi trường của worker

Biến Mặc định Mô tả
TZ UTC Múi giờ
CASHPILOT_UI_URL -- URL của container UI, ví dụ http://cashpilot-ui:8080
CASHPILOT_API_KEY -- Phải khớp với khóa ghi danh của UI. Chỉ cần để ghi danh; sau đó worker dùng khóa riêng của nó
CASHPILOT_WORKER_NAME (hostname) Tên hiển thị của worker này trong bảng điều khiển đội máy
CASHPILOT_WORKER_URL (tự phát hiện) URL mà UI dùng để kết nối tới worker này, ví dụ http://192.168.1.50:8081. Hãy đặt rõ cho đội máy trải trên nhiều máy chủ: việc tự phát hiện có thể báo một IP nội bộ của container mà UI không kết nối được
CASHPILOT_WORKER_BIND_ADDR 127.0.0.1 Chỉ dành cho compose của đội máy và worker từ xa (docker-compose.fleet.yml): giao diện mạng của máy chủ mà cổng API Docker-socket của worker được công bố, mặc định là loopback. docker-compose.yml mặc định hoàn toàn không công bố cổng 8081. API của worker có thể triển khai/dừng bất kỳ container nào (= quyền root trên máy chủ), nên với worker từ xa hãy bind vào một giao diện riêng/VPN (ví dụ một IP Tailscale), không bao giờ vào IP công khai
CASHPILOT_PORT 8081 Cổng mà worker thông báo cho UI. Nó không thay đổi cổng lắng nghe, vốn cố định bởi CMD của image; xem tài liệu tham khảo cấu hình

Ví dụ 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

Đây là file thật

Khối ở trên được chèn nguyên văn từ docker-compose.yml trong kho mã, nên nó không thể lệch khỏi những gì thực sự được phát hành. Trước đây, một bản chép tay của nó đã công bố API Docker-socket của worker trên mọi giao diện mạng và ghim :latest, cả hai điều mà trang mặc định bảo mật dặn bạn đừng làm.

Quyền truy cập Docker socket

Worker quản lý container của các dịch vụ qua Docker, nhưng nó không mount /var/run/docker.sock. Container cashpilot-socket-proxy giữ socket và chỉ chuyển cho worker những lệnh gọi mà worker thực hiện, từ chối các container đặc quyền và các bind của thư mục máy chủ mà bạn chưa liệt kê (những gì nó từ chối). Bản cập nhật trong ứng dụng là tùy chọn bật: nó chỉ chạy khi có CASHPILOT_COMPOSE_DIR=<this folder> trong .env cạnh file compose, và thiết lập đó cho phép container bind thư mục ấy, làm proxy yếu đi (cái giá của nó). Hãy để trống và cập nhật bằng docker compose pull && docker compose up -d. Worker vẫn kiểm soát mọi container trên máy chủ, nên để bảo mật tốt nhất, hãy chạy CashPilot trên một máy hoặc VLAN riêng.

Lưu giữ khóa bí mật

Thông tin đăng nhập được mã hóa bằng CASHPILOT_ENCRYPTION_KEY, không phải CASHPILOT_SECRET_KEY, khóa này chỉ ký các phiên đăng nhập. Khóa mã hóa được tự tạo ở lần chạy đầu và lưu tại /data/.fernet_key. Hãy sao lưu file đó. Nếu volume được tạo lại mà không có nó, một khóa mới sẽ được tạo và mọi thông tin đăng nhập đã lưu sẽ vĩnh viễn không đọc được. Việc đặt CASHPILOT_ENCRYPTION_KEY là để khôi phục bản sao lưu đó; file khóa luôn được ưu tiên, nên đặt nó trên một bản cài đang hoạt động tốt sẽ không thay đổi gì.

Mật khẩu và bí mật trong UI

Bạn có thể đổi mật khẩu của mình bất cứ lúc nào từ menu ảnh đại diện -> Change password (Đổi mật khẩu) (mọi vai trò đều dùng được); việc này đăng xuất các phiên khác của bạn. Trong Settings (Cài đặt), các bí mật đã lưu chỉ ghi được: nhập một giá trị để thay đổi, hoặc để trống trường để giữ giá trị hiện có. Thông tin đăng nhập đã lưu không bao giờ được gửi lại trình duyệt.

Cập nhật CashPilot

File compose ghim một dòng phiên bản major.minor, như drumsergio/cashpilot:X.Y, nên pull sẽ tải bản vá mới nhất của dòng đó:

docker compose pull
docker compose up -d

docker compose pull tải image mới nhất đã được phát hành và up -d chỉ tạo lại những container có image thay đổi. Các file compose được phát hành đặt pull_policy: always, nên ngay cả một lệnh docker compose up -d đơn thuần cũng sẽ kéo image mới nhất trước.

Từ bảng điều khiển. Settings (Cài đặt), About and updates (Giới thiệu và cập nhật) chạy cùng hai lệnh đó cho bạn từ một container trợ giúp tồn tại trong thời gian ngắn. Container trợ giúp đọc các file compose của bạn và .env nằm cạnh chúng (hoặc các file bạn đã truyền bằng --env-file), không bao giờ đọc shell mà bạn dùng để khởi động CashPilot. Giả sử bạn khởi động nó bằng CASHPILOT_UI_PORT=8088 docker compose up -d. Bản cập nhật sẽ đưa bảng điều khiển về lại cổng 8080, nên nó dừng lại và cho bạn biết lý do thay vì làm vậy. Hãy đưa giá trị đó vào .env và nút sẽ hoạt động.

Bạn không cần build lại

CashPilot phát hành sẵn các image đa kiến trúc trên Docker Hub (drumsergio/cashpilot, drumsergio/cashpilot-worker). docker compose build / --build chỉ liên quan nếu bạn cố ý build từ mã nguồn bằng docker-compose.build.yml. Với các bản cài thông thường, pull + up -d là quy trình cập nhật đầy đủ và đúng.

Ghim một phiên bản cụ thể

Để ở lại một bản phát hành chính xác, hãy thay tag dòng phiên bản X.Y trong docker-compose.yml bằng tag phát hành đầy đủ X.Y.Z trên cả drumsergio/cashpilot và drumsergio/cashpilot-worker (luôn cùng một tag trên cả hai), và xóa pull_policy: always. Xem các tag trên Docker Hub.

Để chuyển sang một dòng phiên bản mới hơn, hãy sửa cả hai tag: trên máy chủ UI trước, rồi trên mọi máy chủ worker. Hãy đọc UPGRADING.md trước, vì một bản phát hành lớn như 3.0 có các bước riêng.

Tự động cập nhật (tùy chọn)

Nếu bạn muốn cập nhật không cần can thiệp, hãy cho một trình lập lịch chạy cùng hai lệnh đó, ví dụ với một mục cron hằng ngày:

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

Hoặc chạy một công cụ tự cập nhật như Watchtower hay Diun cho các container CashPilot. Những công cụ này là tùy chọn. CashPilot không đi kèm trình cập nhật nào.

Dọn dẹp image cũ

CashPilot chỉ xóa một image sau khi một bản cập nhật image ứng dụng đã thay thế nó, và chỉ trên worker có Docker socket gốc. Ngoài trường hợp đó, mỗi lần cập nhật và mỗi lần triển khai lại có thể để lại image trước đó trên đĩa. Trên một đội máy thử nghiệm gồm ba máy chủ, các image CashPilot và ứng dụng kiếm tiền cũ tổng cộng khoảng 3 GB. Con số đó nhỏ so với những gì các chương trình khác trên cùng máy chủ thường để lại, nên hãy xem toàn bộ máy chủ:

docker system df

Giá trị RECLAIMABLE trên dòng Images là dung lượng Docker có thể giải phóng.

Vì sao CashPilot không làm việc này cho bạn. Worker kết nối tới Docker qua socket proxy. Với image, proxy cho phép nó kéo một image và đọc một image theo tên, ngoài ra không gì khác. Nó không thể liệt kê image của máy chủ hay xóa image nào. Một worker làm được điều đó cũng sẽ thấy và xóa được image của mọi chương trình khác trên máy chủ. Xem những gì proxy từ chối.

Bước 1: xóa các image lơ lửng (dangling). Một image lơ lửng không có tag và không container nào dùng nó, dù đang chạy hay đã dừng. Một lần cập nhật qua tag di động như X.Y (một dòng phiên bản như dòng mà các file compose ghim), latest hoặc một digest để lại chính những image này:

docker image prune

Lệnh này cũng xóa image bạn đã chạy trước một lần cập nhật qua tag di động: khi image mới của dòng đó về, image cũ không còn tag. Để giữ đường quay lại, hãy ghi lại phiên bản chính xác trước khi cập nhật (chân thanh bên hiển thị nó), để bạn có thể kéo lại drumsergio/cashpilot:<X.Y.Z>. Hoặc ghim file compose vào một tag X.Y.Z chính xác; khi đó image cũ giữ tag của nó và áp dụng bước 2.

Docker sẽ hỏi trước khi xóa. Trong một mục cron, hãy thêm --force để bỏ qua câu hỏi. Nó không thay đổi gì khác:

30 4 * * 0  docker image prune --force

Đừng thêm -a

docker image prune -a xóa mọi image mà hiện không container nào dùng, dù lơ lửng hay có tag. Điều đó bao gồm image của các stack bạn đã cố ý dừng và image bạn tự build trên máy mà không thể kéo lại.

Bước 2: xóa các tag đã ghim cũ. Một image được ghim vào một phiên bản vẫn giữ tag sau khi bạn chuyển sang phiên bản mới hơn, nên prune bỏ qua nó. Các image CashPilot sau được ghim:

Kho Cái gì ghim nó
drumsergio/cashpilot File compose (một dòng phiên bản cũ, hoặc một phiên bản chính xác bạn đã ghim)
drumsergio/cashpilot-worker File compose, giống như trên
drumsergio/cashpilot-tunnel Worker, mỗi phiên bản worker một tag
drumsergio/cashpilot-earnapp Mục EarnApp trong danh mục
drumsergio/cashpilot-anyone Mục Anyone Protocol trong danh mục

Điều tương tự áp dụng cho image của một dịch vụ bạn đã gỡ: tag của nó còn đó cho đến khi bạn xóa nó. Một image trong danh mục được ghim theo digest, như MystNodes hoặc ProxyBase, mất tag khi một image mới hơn thay thế nó, nên bước 1 đã bao gồm nó.

Trước tiên hãy liệt kê các tag mà không container nào dùng. Ví dụ này dành cho image worker. Với một kho khác trong bảng, hãy đổi repo:

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

Sau đó xóa từng tag cũ theo tên, mỗi lần một tag:

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

Đừng thêm -f. Không có nó, Docker từ chối xóa một image mà container vẫn đang dùng, dù đang chạy hay đã dừng, và in ra conflict: unable to delete. Khi thấy thông báo đó, hãy giữ image lại. Hãy giữ tag bạn đang chạy và tag bạn đã chạy trước đó, để bạn vẫn có thể lùi lại một phiên bản. Chỉ xóa các tag cũ hơn hai tag đó.

Cột Host disk (Đĩa máy chủ) của bảng điều khiển hiển thị dung lượng trống trên hệ thống file chứa /data của worker. Image thường nằm trên cùng hệ thống file đó, dưới thư mục dữ liệu gốc của Docker, nhưng không phải lúc nào cũng vậy. docker info --format '{{.DockerRootDir}}' hiển thị thư mục dữ liệu gốc của Docker. Với kho image containerd, mặc định trên một bản cài Docker Engine 29 mới, image nằm dưới thư mục gốc của containerd, thường là /var/lib/containerd. docker info --format '{{.Driver}}' in ra overlayfs với kho image containerd và overlay2 với kho kiểu cũ. Hãy kiểm tra dung lượng trống trên hệ thống file chứa thư mục áp dụng cho bạn.

Các dịch vụ được hỗ trợ

CashPilot hỗ trợ 60 dịch vụ đang hoạt động hoặc ở giai đoạn beta, trong năm nhóm:

  • Chia sẻ băng thông (19): chia sẻ băng thông internet của bạn để có thu nhập thụ động
  • DePIN (16): các mạng hạ tầng vật lý phi tập trung
  • Điện toán GPU (7): cho thuê GPU của bạn cho các tác vụ AI và điện toán
  • Lưu trữ (3): chia sẻ dung lượng đĩa trên các mạng lưu trữ phi tập trung
  • Đào coin (14): triển khai một trình đào hoặc theo dõi một pool theo địa chỉ nhận thanh toán (Đào coin)

Trong số đó, 30 có thể được triển khai và quản lý tự động qua Docker. Danh mục theo dõi 30 dịch vụ còn lại (19 ứng dụng trình duyệt hoặc máy tính, 7 nút GPU, 4 pool đào coin). CashPilot đọc số dư của chúng ở những nơi có bộ thu thập.

Xem toàn bộ danh mục trong mục Hướng dẫn dịch vụ.

Bước tiếp theo