# Docker Deployment (CI4)

## Quick start
1. Copy `.env.example` to `.env` and adjust domain, ports, database credentials, and `COMPOSE_PROJECT_NAME`.
2. Copy `docker-compose.example.yml` to `docker-compose.yml`.
3. Build and run: `docker compose up -d --build`.

## Per-clone config
- Keep `.env`, `docker-compose.yml`, and `docker-compose.override.yml` local to each clone/domain.
- Set a unique `COMPOSE_PROJECT_NAME` per clone so Docker container, network, and volume names do not collide.
- Set `HTTP_PORT` and `DB_PUBLISHED_PORT` per clone when multiple stacks run on the same host.
- Set `APP_BASE_URL` to the public URL for the clone, for example `https://example.com/`.

## Status and logs
- Status: `docker compose ps`
- Logs: `docker compose logs -f nginx`, `docker compose logs -f app`, `docker compose logs -f scheduler`, `docker compose logs -f db`

## Base URL (CI4)
- Prefer setting `APP_BASE_URL` in `.env`.
- If CodeIgniter config reads CI4 dot keys, also set `app.baseURL=https://example.com/`.
- Behind a reverse proxy, set `app.forceGlobalSecureRequests=true` and `app.proxyIPs=127.0.0.1` as needed.

## Database config
- DB host inside Compose is `db`.
- Use `.env` variables: `DB_HOST`, `DB_PORT`, `DB_NAME`, `DB_USER`, `DB_PASSWORD`, and `DB_ROOT_PASSWORD`.

## Apache reverse proxy (host)
- Enable modules: `proxy`, `proxy_http`, `headers`, `rewrite`, `ssl`.
- Copy `docker/apache/app.example.conf` and `docker/apache/app-ssl.example.conf` into `/etc/apache2/sites-available/` with domain-specific filenames.
- Adjust `ServerName`, `ServerAlias`, SSL certificate paths, and the proxied port to match `HTTP_PORT`.
- Enable the copied site files, then reload Apache.

## Ports
- Docker Nginx listens on `${HTTP_BIND:-127.0.0.1}:${HTTP_PORT:-8081}`.
- MariaDB is published on `${DB_BIND:-127.0.0.1}:${DB_PUBLISHED_PORT:-3307}`.

## Optional Redis
- Start with: `docker compose --profile redis up -d`.
