# Docker Build & Publish Guide

This guide explains how to package the project into Docker images and push them to a registry.

## Prerequisites
- Docker Desktop / Docker Engine
- Network access to the registry
- Registry login credentials

## Files you need
These files are required to build and publish:
- `ems-backend/Dockerfile`
- `ems-frontend/Dockerfile`
- `ems-frontend/nginx.conf`
- `docker-compose.yml` (optional for local test)
- `.env` (do **not** publish; keep secrets local)

## 1) Build images locally
From the project root:
```bash
docker build -t <REGISTRY>/<NAME>/ems-backend:latest ./ems-backend
docker build -t <REGISTRY>/<NAME>/ems-frontend:latest --build-arg VITE_API_BASE_URL=/api ./ems-frontend
```

Examples:
- Docker Hub:
```bash
docker build -t <dockerhub_user>/ems-backend:latest ./ems-backend
docker build -t <dockerhub_user>/ems-frontend:latest --build-arg VITE_API_BASE_URL=/api ./ems-frontend
```
- Private registry:
```bash
docker build -t docker.aizhangz.top/ems-backend:latest ./ems-backend
docker build -t docker.aizhangz.top/ems-frontend:latest --build-arg VITE_API_BASE_URL=/api ./ems-frontend
```

## 2) Login to registry
```bash
docker login <REGISTRY>
```

Examples:
```bash
docker login docker.aizhangz.top
```

## 3) Push images
```bash
docker push <REGISTRY>/<NAME>/ems-backend:latest
docker push <REGISTRY>/<NAME>/ems-frontend:latest
```

Examples (private registry):
```bash
docker push docker.aizhangz.top/ems-backend:latest
docker push docker.aizhangz.top/ems-frontend:latest
```

## 4) Verify
Pull once to confirm:
```bash
docker pull <REGISTRY>/<NAME>/ems-backend:latest
docker pull <REGISTRY>/<NAME>/ems-frontend:latest
```

## Notes
- Never commit `.env` with secrets.
- If using a public registry, remove sensitive configs from images.
- For local run with images, use `docker-compose.hub.yml` or `docker-compose.private.yml`.
