# Run it in a container

The image runs the agent as user 65534, not as root, on a read-only filesystem, with no shell and no installer. It carries certificate roots of its own. Calls go to https://supply.coronium.ai.

## Needs

- Docker on Linux, outbound TCP to the relay, and no inbound port.
- `agent.env` from [enrolment](/guides/device-enrol.md). A person who has none yet makes it with `touch agent.env && chmod 600 agent.env`, then writes three lines into it in an editor, such as `nano agent.env`: `CORONIUM_RELAY=us1.almanac.channel:17001`, `CORONIUM_DEVICE=<device id>` and `CORONIUM_DEVICE_SECRET=<device secret>`, without quotes and never on a command line.
- One container per public address: when an earlier residential device already exits from that address, the later one is withheld as `same_exit`.

No installer shows the agreement here, so the signature and the acceptance stored at enrolment are its record.

## Steps

1. Download, check and load the image. `ARCH` is `amd64` for `x86_64` and `arm64` for `aarch64`.

```sh
umask 077
SUPPLY=${SUPPLY:-https://supply.coronium.ai}
ARCH=amd64
curl -fsSLO "$SUPPLY/kit/SHA256SUMS"
curl -fsSLO "$SUPPLY/kit/coronium-agent-docker-$ARCH.tar"
grep " coronium-agent-docker-$ARCH.tar\$" SHA256SUMS | sha256sum -c
docker load -i "coronium-agent-docker-$ARCH.tar"
curl -fsS "$SUPPLY/kit/index.json" | jq -r .version > coronium-version.txt
```

Expect: `OK`, then `Loaded image: coronium-agent:<version>`, with the version `coronium-version.txt` now holds. Stop if the check fails. Safe to repeat: yes.

2. Run it, beside `agent.env`.

```sh
umask 077
VERSION=$(cat coronium-version.txt)
docker run -d --name coronium-agent --restart unless-stopped --read-only \
  --cap-drop ALL --security-opt no-new-privileges --env-file agent.env "coronium-agent:$VERSION"
docker logs -n 20 coronium-agent
```

Expect: `connected to the relay`. A problem is one line with its cause and its fix. The agent does not retry a refused setting: Docker starts it again with a growing pause until the file is fixed. Docker reads `agent.env` only when it creates the container, so after a change run `docker rm -f coronium-agent` and this step again. Safe to repeat: after `docker rm -f coronium-agent` only; Docker refuses a second container of the same name.

## Stop and remove

`docker stop coronium-agent` stops sharing, and it stays stopped after a reboot; `docker start coronium-agent` starts it again. To remove the container, the settings file that holds the secret, and the image:

```sh
umask 077
VERSION=$(cat coronium-version.txt)
docker rm -f coronium-agent
rm agent.env
docker rmi "coronium-agent:$VERSION"
```

Removing it does not withdraw the device; [the states section](/guides/device-states.md) says how.
