# Troubleshooting FreeBSD Containers

Practical fixes for the most common host, networking, storage, and runtime issues when running FreeBSD-native OCI containers.

If you're using [`fjord`](<https://fjord.daemonless.io>), most host prerequisites (`pf`, `fdescfs`, CNI plugins, and `ocijail` annotations) are checked and configured automatically.

---

## `localhost:<port>` Times Out on the Host

**Symptom:** `curl http://localhost:8080` or opening `http://127.0.0.1:<port>` from the FreeBSD host itself hangs or times out, even though the container is running and reachable from other machines on the LAN.

**Cause:** `pf` `rdr` rules inside `cni-rdr/*` only translate traffic arriving on external or bridge interfaces—they never hairpin host loopback (`lo0`) traffic, even with `net.pf.filter_local=1`.

**Fix:** Test from another machine on your network using the host's LAN IP, or probe the container's bridge IP directly from the host:

```
# Find the container's CNI IP address
podman inspect -f '{{.NetworkSettings.IPAddress}}' <name>

# Probe the container IP directly from the host
curl http://<container-ip>:<port>
```

From another machine on the LAN, open `http://<server-ip>:<port>`.

---

## `ifconfig_DEFAULT="DHCP"` Steals LAN Leases on Container Start

**Symptom:** Starting a container triggers `dhclient` on `epair*` interfaces, floods logs with DHCP requests, steals LAN leases, or breaks host routing.

**Cause:** Fresh FreeBSD VMs often ship with `ifconfig_DEFAULT="DHCP"` in `/etc/rc.conf`. Whenever a container starts and creates a virtual `epair` NIC, `devd` matches `ifconfig_DEFAULT` and launches `dhclient` on the container's interface.

**Fix:** Replace `ifconfig_DEFAULT="DHCP"` with your actual physical/virtual NIC name (for example `vtnet0`, `em0`, or `ix0`) in `/etc/rc.conf`:

```
# Check your host's primary interface name
ifconfig -l

# Replace ifconfig_DEFAULT with your real NIC (example: vtnet0)
sysrc -x ifconfig_DEFAULT
sysrc ifconfig_vtnet0="DHCP"
```

---

## Container-to-Container DNS Fails After Installing `cni-dnsname`

**Symptom:** Containers on the same Compose or custom Podman network cannot resolve each other by service or container name, even after `pkg install cni-dnsname`.

**Cause:** Podman only wires the `dnsname` CNI plugin into networks created **after** `cni-dnsname` is installed. Networks created beforehand (including the default `podman` network or an existing Compose network) do not have `dnsname` in their CNI config.

**Fix:** Stop the stack, remove the old CNI network so Podman recreates it with `dnsname` enabled, and bring the stack back up:

```
# For a Compose stack
podman-compose down
podman network rm <network-name>
podman-compose up -d

# Or inspect existing networks to verify dnsname is configured
podman network ls
podman network inspect <network-name>
```

---

## Switching `storage.conf` from `vfs` to `zfs` Fails

**Symptom:** Changing `driver = "zfs"` in `/usr/local/etc/containers/storage.conf` causes `podman` commands to fail with a driver mismatch error (`database configuration mismatch` or `User-selected graph driver "zfs" overwritten by graph driver "vfs"`).

**Cause:** Podman initialized `/var/db/containers/storage` with `vfs` on first run and refuses to switch storage drivers on an existing graph root.

**Fix:** Stop all containers and reset Podman's container/image cache before editing `storage.conf`. Host bind-mounted `/containers/*` config and media directories are untouched:

```
podman stop -a
podman system reset

# Now set driver = "zfs" and mountopt = "zfsutil" in /usr/local/etc/containers/storage.conf
podman info | grep -i graphDriverName
```

See [ZFS Storage](<https://daemonless.io/guides/zfs/index.md>) for the full `storage.conf` configuration.

---

## Containers Don't Auto-Start After Reboot (`rc.d/podman`)

**Symptom:** Containers work when started manually, but do not come back up after a host reboot (even with `podman_enable="YES"`).

**Cause:** `/usr/local/etc/rc.d/podman` only starts containers created with `--restart always` (`restart: always` in `compose.yaml`). Policies like `unless-stopped` are ignored by the FreeBSD rc script.

**Fix:** Set `restart: always` on containers that should boot with the host, and enable the `podman` service:

```
sysrc podman_enable="YES"
```

```
services:
  myapp:
    image: ghcr.io/daemonless/myapp:latest
    restart: always
```

If you use the Podman API socket (for example with `fjord` or remote clients), restart `podman_service` after running `pkg upgrade` so it picks up updated binaries:

```
service podman_service restart
```

---

## `podman-compose up -d` Exits 0 Without Recreating or Leaves `Created` Orphans

**Symptom:** `podman-compose up -d` returns exit code `0` without updating or starting a broken container, or `podman ps -a` shows a leftover container stuck in `Created` state holding the name or port.

**Cause:** A previous failed start or interrupted recreate left an orphaned container with the same name.

**Fix:** Inspect all containers (including stopped and `Created` ones), force-remove the stuck container, and re-run `podman-compose up -d`:

```
podman ps -a
podman rm -f <name>
podman-compose up -d
```

---

## .NET / CoreCLR Crashes (`Radarr`, `Sonarr`, `Jellyfin`, etc.)

**Symptom:** .NET applications (`Radarr`, `Sonarr`, `Lidarr`, `Prowlarr`, `Jellyfin`) crash immediately on startup with memory-locking, GC, or CoreCLR initialization errors.

**Cause:** .NET requires `allow.mlock` inside the jail, which is disabled by default unless `ocijail` 0.6.0+ receives the OCI annotation.

**Fix:** Verify `ocijail` is `0.6.0` or newer and pass the `allow.mlock` annotation:

```
pkg query %v ocijail

podman run -d --name radarr \
  --annotation 'org.freebsd.jail.allow.mlock=true' \
  ghcr.io/daemonless/radarr:latest
```

See [Jail Permissions (`allow.*`)](<https://daemonless.io/guides/ocijail-patch/index.md>) for Compose syntax and other `allow.*` annotations (`allow.sysvipc` for PostgreSQL, `allow.raw_sockets` for ICMP).

---

## `fdescfs` / `/dev/fd` Errors

**Symptom:** Container startup or scripts fail with `/dev/fd` missing, bad file descriptor errors, or shell process substitution failures.

**Cause:** `fdescfs` is not mounted on `/dev/fd` on the FreeBSD host.

**Fix:** Mount `fdescfs` immediately and persist it in `/etc/fstab`:

```
mount -t fdescfs fdesc /dev/fd
echo 'fdesc /dev/fd fdescfs rw 0 0' >> /etc/fstab
```
