# Docker Setup

This project uses:

- `docker-compose.yml` as the base app definition
- `docker-compose.override.yml` for local development defaults
- a local MySQL container in development
- normal Laravel environment variables for production

## Development

1. Create or keep your normal Laravel `.env` file:

```bash
cp .env.example .env
```

2. Build and start the containers:

```bash
docker compose up --build -d
```

3. If `APP_KEY` is empty, the local app container will generate and persist one
into `.env` automatically on startup.

4. Run migrations and seed the local Docker database:

```bash
docker compose exec app php artisan migrate --seed
```

5. Optional useful commands:

```bash
docker compose exec app php artisan migrate:status
docker compose exec app php artisan test
docker compose exec app php artisan key:generate
docker compose exec app php artisan config:clear
docker compose logs -f app
docker compose exec app bash
```

The app is available at `http://localhost:8080` by default.

## Production

Production should use only the base Compose file and remote DB values supplied
through environment variables or a production env file that is not committed.

Example:

```bash
docker compose -f docker-compose.yml -f docker-compose.prod.yml up --build -d
```

If you use a separate env file for production, point Compose at it:

```bash
APP_ENV_FILE=.env.production docker compose -f docker-compose.yml -f docker-compose.prod.yml up --build -d
```

Production database access is still controlled entirely by Laravel env vars:

- `DB_CONNECTION`
- `DB_HOST`
- `DB_PORT`
- `DB_DATABASE`
- `DB_USERNAME`
- `DB_PASSWORD`
- `DB_URL`
- `MYSQL_URL`
- `PGSQL_URL`

## How Development Avoids the Remote Database

Local development uses `docker-compose.override.yml`, which Docker Compose loads
automatically when you run `docker compose up`.

That override:

- starts a local `db` service
- forces the app container to use `DB_CONNECTION=mysql`
- forces `DB_HOST=db` and local Docker credentials
- clears `DB_URL`, `MYSQL_URL`, and `PGSQL_URL` so remote DSN-style values cannot override `DB_*`
- runs `php artisan config:clear` at container startup so stale cached config does not keep old remote DB settings

Because those values are injected into the container at runtime, the app will
use the local Docker database in development even if your host `.env` contains
remote database credentials.

## Notes

- `.env.docker.example` shows safe Docker-local values you can reference if you
  want a separate Docker-focused env file.
- The container startup script recreates the `public/storage` symlink and fixes
  Laravel writable directories on boot.
- If you change PHP dependencies, rebuild the app image:

```bash
docker compose up --build -d
```
