# MRail Control with Docker Compose

This package starts MariaDB, MRail Control Server and Web from the published
multi-architecture images. ECoS, Z21, Z21 Gateway and Märklin are optional
Compose profiles. The Intellibox/LocoNet adapter and the development-only
Simulator are deliberately not included.

The build output already contains `.env`. When running this file directly from
the source tree, copy `.env.example` to `.env`. Set `MARIADB_PASSWORD` and
`MARIADB_ROOT_PASSWORD` before validating or starting the stack. Persistent data
is stored in the ordinary host directories `./data/database` and `./data/media`.
The media-init service gives the non-root Server process access to its directory.

## Start and update

```sh
docker compose --env-file .env pull
docker compose --env-file .env up -d
```

Compose YAML has no general-purpose `if` statements. Profiles are its native
conditional mechanism. To enable optional components, configure their persistent
adapter ID and host in `.env`, then set, for example:

```dotenv
COMPOSE_PROFILES=ecos,marklin
```

The available values are `ecos`, `z21`, `z21-gateway` and `marklin`. Leave
`COMPOSE_PROFILES` empty for MariaDB, Server and Web only. A command-line
`--profile` remains available as a temporary override.

## Stop

```sh
docker compose --env-file .env down
```

The Compose file deliberately contains no fixed project name. Run its commands
from the same directory so Compose derives the same project identity. Do not
move or rename the directory while the stack is running. A normal `down` removes
containers and its network but retains `./data/database` and `./data/media`.
Because these are host directories, even `down -v` cannot delete their content;
nevertheless, omitting `-v` avoids accidentally removing unrelated named
volumes from additional override files.

Use Docker Compose v2 (`docker compose`). The obsolete v1 command
`docker-compose` is not part of the supported deployment path.

## Ports

- Web: TCP 8080
- REST, SignalR and health: TCP 8081
- adapter gRPC: TCP 8082
- Z21 Gateway profile: UDP 21105 by default
- Märklin profile: UDP 15730 by default

The default bind address for ports 8080, 8081 and 8082 is `0.0.0.0`. Restrict
the corresponding variables or host firewall rules when the services must not
be reachable from every connected network.
