# Docker Deployment

This directory contains Docker configuration for containerized deployment.

{% if use_wheels %}
**Mode:** Dev (local wheels)
{% else %}
**Mode:** Release (PyPI packages)
{% endif %}

## Prerequisites

- Docker Desktop or Rancher Desktop
- Docker Compose (included with Docker Desktop)

## Models

{% for model in models %}
- {{ model.name }}
{% else %}
- (none detected)
{% endfor %}

## Runtime Dependencies

{% if use_wheels %}
The following packages are installed in the container (from pre-built wheels):

{% for package in runtime_packages %}
- {{ package }}
{% endfor %}

The wheels in `wheels/` were built using [uv-monorepo-dependency-tool](https://github.com/TechnologyBrewery/uv-monorepo-dependency-tool)
to convert local path dependencies to pinned version dependencies.
{% else %}
The following packages are installed from PyPI:

{% for package in runtime_packages %}
- {{ package }}
{% endfor %}
{% endif %}

## Quick Start

Build and start the container:

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

The server will be available at http://localhost:{{ http_port }}

## Usage

### Build Only

```bash
docker-compose build
```

### Start in Background

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

### View Logs

```bash
docker-compose logs -f
```

### Stop

```bash
docker-compose down
```

## Testing

Once the container is running, test the endpoint:

```bash
curl -X POST http://localhost:{{ http_port }}/v2/models/<model-name>/infer \
  -H "Content-Type: application/json" \
  -d '{"inputs": [...]}'
```

## Customization

### Environment Variables

The docker-compose.yml supports these environment variables:

- `MLSERVER_HTTP_PORT`: HTTP port (default: {{ http_port }})
- `MLSERVER_GRPC_PORT`: gRPC port (default: {{ grpc_port }})

### Resource Limits

Edit docker-compose.yml to add resource constraints:

```yaml
services:
  mlserver:
    deploy:
      resources:
        limits:
          cpus: '2'
          memory: 4G
```

{% if use_wheels %}
### Rebuilding Wheels

To regenerate the wheels with updated dependencies:

```bash
uv tool run uv-monorepo-dependency-tool build-rewrite-path-deps --version-pinning-strategy=mixed
cp dist/*.whl deploy/docker/wheels/
```

Or re-run the generator:

```bash
oip deploy init --target docker
```
{% else %}
### Updating Dependencies

Edit `requirements.txt` to change package versions, then rebuild:

```bash
docker-compose build --no-cache
```
{% endif %}

## Production Considerations

For production deployments:

1. **Multi-architecture builds**: Use `docker buildx` for ARM/AMD64 support
2. **Registry**: Push to a container registry (Docker Hub, ECR, GCR, etc.)
3. **Secrets**: Use Docker secrets or environment variable injection
4. **Health checks**: The Dockerfile includes MLServer health endpoints
5. **Logging**: Configure structured logging for your platform

## Troubleshooting

**Build fails with package not found:**
{% if use_wheels %}
- Regenerate wheels: `oip deploy init --target docker`
{% else %}
- Ensure runtime packages are published to PyPI
- Check network connectivity to PyPI
{% endif %}

**Container exits immediately:**
- Check logs: `docker-compose logs`
- Verify model-settings.json files are valid JSON

**Port already in use:**
- Stop other services on port {{ http_port }}/{{ grpc_port }}
- Or change the ports in docker-compose.yml
