# 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), in the folder every block works in: `~/coronium` unless `CORONIUM_DIR` names another. A person who has none yet makes it there 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}
mkdir -p "${CORONIUM_DIR:-$HOME/coronium}"
cd "${CORONIUM_DIR:-$HOME/coronium}" || exit
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
cd "${CORONIUM_DIR:-$HOME/coronium}" || exit
VERSION=$(cat coronium-version.txt)
chmod 600 agent.env
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"
for second in $(seq 20); do docker logs coronium-agent 2>&1 | grep -q 'connected to the relay' && break; sleep 1; done
docker logs -n 20 coronium-agent
```

Expect: `connected to the relay`, once the agent has connected: the block waits for that line for a short while before it prints the log. 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.

## If it is not connected

```sh
umask 077
cd "${CORONIUM_DIR:-$HOME/coronium}" || exit
docker start coronium-agent
docker logs -n 5 coronium-agent
```

The first line starts a container that stopped; the second shows why it is not connected, if it is not. With `--restart unless-stopped` Docker starts it again after a restart of the machine, unless you stopped it yourself.

## Update

`/kit/index.json` names the published `version`, and publishing a newer image does not stop a container that is running. To update, run step 1 again, which checks the new image before it is loaded, then `docker rm -f coronium-agent` and step 2. `agent.env` stays as it is. `docker rmi coronium-agent:<old version>` removes the image it replaced.

## Stop and remove

Stop, remove, withdraw: [update, stop, remove and withdraw](/guides/device-lifecycle.md).
