# Usage with application containers

## Use with Podman

### Preparation

Set the following in `~/.config/containers/containers.conf` (or `/etc/containers/containers.conf`):
```toml
[containers]
no_hosts=true
```

```shell
./utils/init.sh # initialize data
```

### Build and run

```shell
./utils/build.sh
```

### TLS certificates

```shell
podman-compose run -u root core certbot register
podman-compose run -u root core certbot register --test-cert
podman-compose run -u root core cat /etc/letsencrypt/accounts/acme-v02.api.letsencrypt.org/directory/*/regr.json
podman-compose run -u root core find /etc/letsencrypt/accounts/ -name regr.json -exec cat {} \;
# Set CAA records for servnest.test and ht.servnest.test
podman-compose exec -u root core certbot certonly --config "/etc/letsencrypt/servnest.ini" -d "servnest.test"
podman-compose exec -u root core certbot certonly --config "/etc/letsencrypt/servnest.ini" -d "ht.servnest.test"
podman-compose exec -u root core certbot certonly --config "/etc/letsencrypt/servnest-dns.ini" -d "*.ht.servnest.test" --cert-name "*.ht.servnest.test"
# Update certificates paths in conf/nginx/
```

### Secondary DNS

Optionally, to enable the `knot-secondary` service, uncomment `notify:` lines in `knot.conf`, then:
```shell
podman-compose --profile=secondary up knot knot-secondary # generate QUIC keys
./utils/setup-xoq.sh # setup mutual XFR over QUIC
```

### Test

```shell
./utils/check.sh
```

#### Test without public IP

Before running `check.php`:

- Set [`local_only_check`](https://servnest.niv.re/back/configuration#local_only_check) to `false` in `config.ini`.
- Add the following configuration to `/etc/hosts` on the host system:
```
::1 servnest.test
::1 ht.servnest.test
::1 sftp.servnest.test
```
- For `ht`, the subdomain and dedicated site tests will fail anyway.

### Bugs

When running `up`, the only expected error messages are:
> [sftpgo] | WRN provider initialized but data loading failed: stat sftpgo.db: no such file or directory
> [tor]    | [warn] You are running Tor as root. You don't need to, and you probably shouldn't.

### Delete old images

```shell
podman images prune
```

### Reset

```shell
podman container rm --all
podman image rm --all
podman rm $(podman container list --external -q)
docker rm $(docker ps -qa)
docker image rm -f $(docker image list -q)
```

## Use with rootless Docker

```shell
export DOCKER_HOST=unix:///run/user/$(id -u)/docker.sock
```

Then use the instructions for Podman but replace `podman` with `docker` in command names.
