# Container deployment

[Documentation index](../README.md)

Run Pi Herdsman in a portable SSH-accessible environment with Pi, Herdr,
developer tools and persistent storage.

## Quick start

Requires Docker Compose v2 (Docker Desktop on Windows).

**Linux/macOS**

```sh
curl -fsSL https://raw.githubusercontent.com/boadij/pi-herdsman/main/scripts/docker-setup.sh | bash
```

**Windows (PowerShell)**

```powershell
irm https://raw.githubusercontent.com/boadij/pi-herdsman/main/scripts/docker-setup.ps1 | iex
```

The guided installer prepares a fresh deployment or preserves an existing
configuration. Authorize your workstation's SSH public key when prompted.
Windows guided setup supports standard Docker with named volumes.
See [guided setup behavior](container-configuration.md#guided-setup-behavior)
for existing installations, key handling and sudo.

### Direct Compose setup

If you prefer manual setup, download [compose.yaml](../../compose.yaml):

```sh
mkdir -p pi-herdsman && cd pi-herdsman
curl -fsSLO https://raw.githubusercontent.com/boadij/pi-herdsman/main/compose.yaml
SSH_AUTHORIZED_KEYS="$(cat ~/.ssh/id_ed25519.pub)" docker compose up -d
```

Choose optional networking or storage before starting if needed.

### Connect

```sh
ssh -p 2222 herdsman@localhost
```

Replace `localhost` with the Docker host's address when connecting remotely.
The default SSH port is exposed on the host's network interfaces; restrict
network access appropriately. Authentication uses SSH keys, not passwords.

Herdr opens automatically. Select a workspace, run `pi` and use `/login`
if model-provider authentication is needed.

## Choose a deployment option

| If you want to...                    | Read                                                       |
| ------------------------------------ | ---------------------------------------------------------- |
| Connect privately over a tailnet     | [Tailscale](#use-tailscale)                                |
| Store the home directory on the host | [Host bind mount](#use-a-host-bind-mount)                  |
| Update Pi, Herdsman or the image     | [Maintenance](#update)                                     |
| Manage web access or extra tools     | [Web access](#web-access) · [Tools](#install-another-tool) |

## Use Tailscale

[Tailscale setup](container-configuration.md#use-tailscale) covers the optional
Compose overlay, authentication, key removal, DNS and connection.

## Use a host bind mount

[Bind-mount setup](container-configuration.md#use-a-host-bind-mount) covers
UID/GID, host permissions and Compose file selection. Changing the storage
of an existing deployment requires a separate data migration.

## Add it to Herdr

```sh
herdr machine add ssh://herdsman@your-host:2222 --label my-herd
```

With an existing `~/.ssh/config` host:

```sh
herdr machine add my-herd --label my-herd
```

The remote machine then appears alongside Local in Herdr.

For authorized SSH onboarding or reciprocal Herdsman peer setup, use the
bundled [machine-pairing skill](../../skills/machine-pairing/SKILL.md).

## Forward your SSH agent

For private Git repositories:

```sh
ssh -A -p 2222 herdsman@your-host
```

### Authorize outbound SSH

On first start, the container also generates a passphrase-free Ed25519 SSH
**client** key if no client key pair exists. The private key stays in the
persistent `/home/herdsman/.ssh` directory and is never regenerated on
restarts. To authorize outbound SSH access on another machine, obtain the
public key from the Docker host:

```sh
docker compose exec herdsman cat /home/herdsman/.ssh/id_ed25519.pub
```

Add that key to the destination's `authorized_keys`. Never copy the private
key. The container recovers a missing public key from an existing unencrypted
private key, but does not overwrite incomplete or unusable identities. Protect
the persistent home volume because the client private key has no passphrase.

## Update

See [Maintain a container deployment](container-maintenance.md) for the
separate Pi, package and image update procedures. Finish active work before
recreation; running processes do not survive it.

### Use a local development package

Keep the checkout in persistent storage accessible inside the container, such
as under `/home/herdsman`. From the container, switch explicitly from the
published package to the checkout:

```sh
pi remove npm:pi-herdsman
cd ~/path/to/pi-herdsman
npm run build
pi install .
pi list
```

To switch back, remove the local selection using its path as shown by
`pi list`, then install the published package:

```sh
pi remove ~/path/to/pi-herdsman
pi install npm:pi-herdsman
pi list
```

Reload affected Pi sessions after switching.

See [local package details](container-maintenance.md#local-development-package-details)
for package-selection conflicts, peer launcher behavior and build updates.

## Web access

See [Web access](container-maintenance.md#web-access) for the bundled extension,
package removal and researcher-specific configuration.

## Install another tool

See [Install another tool](container-maintenance.md#install-another-tool).

## What persists?

| Path                    | Contents                                                                          |
| ----------------------- | --------------------------------------------------------------------------------- |
| `/home/herdsman`        | Pi and Herdr state, repositories, config, credentials, SSH state, installed tools |
| `/var/lib/herdsman/ssh` | SSH server identity                                                               |

Running processes do not survive a container restart. Named volumes survive
`docker compose down`, but `docker compose down -v` deletes them; do not use
`-v` when retaining state.

Run only one active Herdsman runtime against a writable home volume. Linux
lock recovery verifies process identity within the current PID namespace;
independent containers sharing that volume are not supported. Existing Linux
locks without process identity are recovered only when their recorded PID is
absent; an occupied PID remains ambiguous and must be resolved after its
original process has exited.

## Defaults

| Setting            | Default       |
| ------------------ | ------------- |
| SSH port           | `2222`        |
| User               | `herdsman`    |
| Tailscale hostname | `pi-herdsman` |
| Password login     | disabled      |
| Root SSH login     | disabled      |

For direct Compose deployments, `SSH_AUTHORIZED_KEYS` initializes authorization
on first start; it does not add keys to an existing nonempty `authorized_keys`.
Guided setup can add explicitly supplied public keys while preserving existing
authorization.

Pi sessions automatically receive the container environment context from `/AGENTS.md`.

See the [Herdr machine documentation](https://herdr.dev/docs/connecting-machines/) for machine and SSH configuration.
