# Docker

Source: https://tiltas.openpanel.sh/docs/devices/docker

> Run Tiltas in a container with docker run or Compose, share your LAN, update and remove it.

The Tiltas image adds the computer it runs on to your Network as a Server. It runs on 64-bit Linux (amd64 and arm64),
keeps its sign-in in a volume, and can share your home LAN with your other Devices.

## 1. Get a Join key

1. In the [console](/app), open **Join keys** and choose **Create Join key**.
2. Name it after the machine, such as “home-server”. Leave **Reusable** off: the key then adds one Server and is spent.
3. Create it and copy the key, which starts with `qlj_`. It is shown once and works for 7 days unless you chose
   otherwise.

## 2. Start the container

```bash
docker run -d --name tiltas --restart unless-stopped \
  --network host --cap-add NET_ADMIN --device /dev/net/tun \
  -v tiltas-state:/var/lib/tiltas \
  -e TILTAS_JOIN_KEY=qlj_your_join_key \
  -e TILTAS_HOSTNAME=home-server \
  tiltas-registry.openpanel.sh/tiltas/tiltas:latest
```

- `--network host` puts the host itself in your Network: other Devices reach the machine, not just the container.
  Without it the container is a Device of its own.
- `--cap-add NET_ADMIN --device /dev/net/tun` give kernel networking. Without them the image uses
  [userspace networking](#kernel-or-userspace-networking) by itself.
- `tiltas-state` holds the Device's sign-in. Keep it: a restarted or updated container is then the same Device and never
  joins again.
- The Join key is read on the first start only. A single-use key is spent then, so it does no harm that
  `docker inspect` shows it.

### Or with Docker Compose

This keeps the Join key in a file, passed in as a Docker secret.

```yaml title="compose.yaml"
services:
  tiltas:
    image: tiltas-registry.openpanel.sh/tiltas/tiltas:latest
    container_name: tiltas
    restart: unless-stopped
    network_mode: host
    cap_add: [NET_ADMIN]
    devices: ["/dev/net/tun:/dev/net/tun"]
    environment:
      TILTAS_HOSTNAME: home-server
      # TILTAS_ROUTES: 192.168.1.0/24
    secrets:
      - source: join_key
        target: tiltas_join_key
    volumes:
      - ./state:/var/lib/tiltas

secrets:
  join_key:
    file: ./join_key
```

```bash
echo qlj_your_join_key > join_key && chmod 600 join_key
docker compose up -d
```

## 3. Check that it is online

```bash
docker logs tiltas
```

The first lines say how it started:

```text title="Output" noCopy
tiltas: kernel networking (interface tiltas0)
tiltas: signing in
```

```bash
docker exec tiltas tiltas device
```

```text title="Output" noCopy
Device ID  dev_738arbrsr2
Address    100.64.0.1
Name       home-server
Panel      https://tiltas.openpanel.sh
```

`docker ps` shows the container as `(healthy)` once it is connected. In the console, **Devices** lists `home-server` as
**Online**. It is a Server: other Devices reach it only where an [Access rule](/docs/access) or a
[Service](/docs/services) allows.

Without a Join key, the log prints a link and a code instead. Approving the code adds the container as the Personal
device of whoever approves it, so use a Join key for anything that should belong to the Account.

## 4. Share your home LAN

One Device can give your other Devices the whole LAN behind it: the router, a printer, a camera, things that cannot run
Tiltas. Your LAN is the network your router hands out, written as a subnet: a NAS at `192.168.1.20` with the mask
`255.255.255.0` is on `192.168.1.0/24`.

Add `-e TILTAS_ROUTES=192.168.1.0/24` to the command (in Compose, uncomment the line) and start the container again
from the same volume; the Join key is not used again. Then:

1. In the console, open **Devices**, then `home-server`. Under **Subnet routes** the LAN shows as **Offered**: switch it
   on to approve it.
2. Open **Access rules** and choose **Add a rule**: under **Who**, who may use the LAN; under **May reach**, a
   **Subnet**, `192.168.1.0/24`, with ports if you want to narrow it.

Nothing reaches the LAN until both are done: approving shares the route, the rule says who may use it. Tiltas's apps
and `tiltas up` use approved routes by themselves, so your laptop can then open `http://192.168.1.1` (your router, say)
from anywhere. More in [Subnet routers](/docs/access/subnet-routers).

With `--network host`, Docker has already turned on IP forwarding on the host. Without it, add
`--sysctl net.ipv4.ip_forward=1` in kernel networking; the log warns when forwarding is off.

## Kernel or userspace networking

| | Kernel | Userspace |
|---|---|---|
| Needs | `NET_ADMIN` and `/dev/net/tun` | Nothing |
| Other Devices reach the host | Yes, on the ports rules allow | Yes: connections go to the same port on the host (with host networking) |
| Shares your LAN | Yes | Yes |
| Programs on the host reach other Devices | Yes, by address | Only through a SOCKS5 proxy (`TILTAS_DAEMON_FLAGS=--socks5-server=localhost:1055`), and not LANs that other Devices share |

The image picks kernel networking when it has both, and says which one it uses in its first log line. If Tailscale
also runs on the same host in kernel mode, both use addresses in `100.64.0.0/10` and get in each other's way: run Tiltas
in userspace networking there. See [Tiltas and Tailscale on one machine](/docs/troubleshooting/tailscale).

## Settings

| Variable | What it does |
|---|---|
| `TILTAS_JOIN_KEY` | The Join key. Used on the first start only. |
| `TILTAS_JOIN_KEY_FILE` | A file holding the Join key instead. `/run/secrets/tiltas_join_key` (a Docker secret) is read by itself when present. |
| `TILTAS_HOSTNAME` | The Device's name, given on the first start. Rename it later in the console. |
| `TILTAS_ROUTES` | Subnets to share, comma-separated, such as `192.168.1.0/24`. Applied on every start; set but empty stops sharing. |
| `TILTAS_USERSPACE` | `auto` (default): kernel networking when the container has `NET_ADMIN` and `/dev/net/tun`, else userspace. `true` or `false` to choose. |
| `TILTAS_UP_FLAGS` | More `tiltas up` flags in `--flag=value` form, such as `--accept-dns=false`. Later starts apply the ones that are settings. |
| `TILTAS_DAEMON_FLAGS` | More `tiltasd` flags, such as `--socks5-server=localhost:1055`. |
| `TILTAS_PANEL` | A Panel other than `https://tiltas.openpanel.sh`. |
| `TILTAS_STATE_DIR` | Where the state is kept, `/var/lib/tiltas` by default. |

Any `tiltas` command runs in the container, such as `docker exec tiltas tiltas status`.

## Update

```bash
docker pull tiltas-registry.openpanel.sh/tiltas/tiltas:latest
docker rm -f tiltas
# then the same docker run command as above
```

With Compose: `docker compose pull && docker compose up -d`. The new container finds the sign-in in the volume and
reconnects as the same Device:

```text title="Output" noCopy
tiltas: signed in before: reconnecting with the stored Device token
```

Stopping or restarting the container never removes the Device. To run a known version instead of `latest`, use its tag:
`docker exec tiltas tiltas version` prints the version you run, and its long version is the image's tag.

## Remove

```bash
docker exec tiltas tiltas logout
docker rm -f tiltas
docker volume rm tiltas-state
```

`tiltas logout` removes the Device from your Network, as removing it in the console does. If you only delete the
container, the Device stays listed as offline: remove it under **Devices**.
