---
title: Deployment Guide
product: plant-health-prediction-using-cnn
doc_type: guide
version: main
source: git2docs (code-derived, validation-filtered)
canonical: https://git2docs.com/source2books/docs/plant-health-prediction-using-cnn/plant-disease-predictor/deployment-guide
---

# Deployment Guide

_Deploying to production (Docker, Kubernetes, serverless)_

## Overview

This guide walks you through deploying the Plant Disease Predictor application to a production environment using Docker. Whether you are running the application on a single server or planning to scale it further, containerizing the app ensures a consistent, reproducible environment across machines. Following these steps will have your leaf-image analysis service running reliably for your end users.

## Prerequisites

Before you begin, make sure you have the following in place:

- **Docker** installed on your host machine (Docker Engine 20.10+ recommended)
- **Python 3.10** (used inside the container; no local Python installation required if using Docker exclusively)
- The complete project source code, including:
  - `main.py` — the Streamlit application entry point
  - `requirements.txt` — all Python dependencies
  - `config.toml` — Streamlit configuration file
  - `credentials.toml` — Streamlit credentials file
  - `Dockerfile` — provided in the project root
- Network access to pull the `python:3.10-slim` base image from Docker Hub
- Port `80` available and open on your host machine or cloud firewall rules

> **Note for reviewer:** No Kubernetes or serverless deployment configuration (e.g., Helm charts, `kubernetes.yaml`, AWS Lambda handlers) was found in the source material. This guide covers Docker deployment only. Kubernetes and serverless sections should be added once those assets are available.

## Installation

Follow these steps to build and run the Plant Disease Predictor container.

**Step 1 — Clone or download the project**

Ensure all project files are present in a single directory on your host machine before proceeding.

```bash
ls
# You should see: main.py  requirements.txt  config.toml  credentials.toml  Dockerfile
```

**Step 2 — Build the Docker image**

From the project root directory, run the following command. The `-t` flag tags the image with a recognizable name so you can reference it easily later.

```bash
docker build -t plant-disease-predictor .
```

Docker will:
1. Pull the `python:3.10-slim` base image.
2. Copy your project files into the `/app` directory inside the container.
3. Install all dependencies listed in `requirements.txt`.
4. Copy your Streamlit configuration files into the container's home directory.
5. Expose port `80` for HTTP traffic.

**Step 3 — Run the container**

Start the container and map port `80` inside the container to port `80` on your host:

```bash
docker run -p 80:80 plant-disease-predictor
```

The application will start automatically using Streamlit and run `main.py`.

**Step 4 — Verify the deployment**

Open a browser and navigate to:

```
http://localhost
```

You should see the Plant Disease Predictor web interface, ready to accept leaf images.

## Configuration

The container's behavior is controlled by two Streamlit configuration files that you must provide before building the image. Both files are copied into the container at build time and cannot be changed without rebuilding the image.

| File | Location in container | Purpose |
|---|---|---|
| `config.toml` | `~/.streamlit/config.toml` | Controls Streamlit server settings such as the port, theme, and whether CORS is enabled |
| `credentials.toml` | `~/.streamlit/credentials.toml` | Manages Streamlit telemetry and authentication opt-outs |

**Port configuration**

The container exposes port `80` by default, which is the standard HTTP port. If your infrastructure requires a different external port, you can remap it at runtime without changing the Dockerfile:

```bash
# Remap internal port 80 to external port 8080
docker run -p 8080:80 plant-disease-predictor
```

**`config.toml` key settings to review before production**

Open your local `config.toml` and confirm or set the following values before building:

```toml
[server]
port = 80                  # Must match the EXPOSE value in the Dockerfile
enableCORS = false         # Set to true only if your frontend is served from a different origin
headless = true            # Required for running in a containerized/server environment
```

Setting `headless = true` is critical for production — without it, Streamlit may attempt to open a browser window on the server, which will fail in a containerized environment.

> **Note for reviewer:** The actual contents of `config.toml` and `credentials.toml` were not included in the source material. The settings above reflect standard Streamlit production best practices. Please verify against the real files before publishing.

## Usage

Once the container is running, your users interact with the application through a standard web browser — no additional client software is needed.

**Uploading a leaf image**

1. Navigate to `http://your-server-address` (or `http://localhost` for local testing).
2. Use the file upload widget on the main page to select a leaf image from your device.
3. Supported formats are those accepted by the CNN model (typically `.jpg`, `.jpeg`, and `.png`).
4. Submit the image to trigger the prediction.

**Receiving a disease prediction**

After uploading, the application passes your image through the CNN model and returns:
- The predicted disease name (or a healthy classification).
- A confidence score indicating how certain the model is about the prediction.

**Running the container in detached mode**

For persistent production deployments, run the container in the background so it continues operating after you close your terminal session:

```bash
docker run -d -p 80:80 --name plant-disease-predictor plant-disease-predictor
```

To check that it is still running:

```bash
docker ps
```

To stop the service:

```bash
docker stop plant-disease-predictor
```

> **Note for reviewer:** API endpoint details (request/response formats, authentication, error codes) were not present in the source material. If a REST API layer exists alongside the Streamlit interface, those details should be added to a dedicated API reference page.

## Examples

**Example 1 — Build and run for the first time**

This is the complete sequence from a fresh clone to a running service.

```bash
# Step 1: Build the image
docker build -t plant-disease-predictor .

# Step 2: Run in detached mode on port 80
docker run -d -p 80:80 --name plant-disease-predictor plant-disease-predictor

# Step 3: Confirm the container is running
docker ps
```

Expected output from `docker ps`:

```
CONTAINER ID   IMAGE                      COMMAND                  STATUS         PORTS
a1b2c3d4e5f6   plant-disease-predictor    "streamlit run main.…"   Up 3 seconds   0.0.0.0:80->80/tcp
```

---

**Example 2 — Run on a non-standard port**

If port `80` is already in use on your server, remap the container to port `8501`:

```bash
docker run -d -p 8501:80 --name plant-disease-predictor plant-disease-predictor
```

Your application is then accessible at `http://your-server-address:8501`.

---

**Example 3 — View application logs**

If you need to inspect what the application is doing (useful for monitoring predictions or catching errors), stream the container logs in real time:

```bash
docker logs -f plant-disease-predictor
```

Expected output (abbreviated):

```
  You can now view your Streamlit app in your browser.

  Network URL: http://0.0.0.0:80
  External URL: http://<your-server-ip>:80
```

---

**Example 4 — Rebuild after a code change**

After modifying `main.py` or any project file, stop the old container, rebuild the image, and restart:

```bash
docker stop plant-disease-predictor
docker rm plant-disease-predictor
docker build -t plant-disease-predictor .
docker run -d -p 80:80 --name plant-disease-predictor plant-disease-predictor
```

## Troubleshooting

Use this section to diagnose and resolve the most common issues encountered during deployment.

---

**Issue: Port 80 is already in use**

- **Symptom:** `docker run` fails with an error such as `Bind for 0.0.0.0:80 failed: port is already allocated`.
- **Likely cause:** Another process or container on your host is already listening on port 80.
- **Fix:** Either stop the conflicting process, or remap the container to a free port:
  ```bash
  docker run -d -p 8501:80 --name plant-disease-predictor plant-disease-predictor
  ```

---

**Issue: `config.toml` or `credentials.toml` not found during build**

- **Symptom:** The `docker build` step fails with a `COPY` error, such as `COPY failed: file not found in build context`.
- **Likely cause:** One or both configuration files are missing from your project root directory.
- **Fix:** Ensure `config.toml` and `credentials.toml` exist in the same directory as your `Dockerfile` before running `docker build`.

---

**Issue: Application starts but browser shows a blank page or connection refused**

- **Symptom:** Navigating to `http://localhost` or your server IP returns no response or a blank page.
- **Likely cause:** `headless` mode is not set to `true` in `config.toml`, or the container's port mapping is incorrect.
- **Fix:** Verify your `config.toml` contains `headless = true` under `[server]`, then rebuild the image and restart the container.

---

**Issue: Dependency installation fails during `docker build`**

- **Symptom:** The build fails at `RUN pip install -r requirements.txt` with package resolution or network errors.
- **Likely cause:** Missing or malformed `requirements.txt`, or no internet access from the build host.
- **Fix:** Confirm `requirements.txt` is present and valid. If behind a corporate proxy, configure Docker's proxy settings before building.

---

**Issue: Container exits immediately after starting**

- **Symptom:** `docker ps` shows no running containers; the container appears briefly then stops.
- **Likely cause:** `main.py` contains a startup error, or a required model file is missing from the image.
- **Fix:** Inspect the logs immediately after the crash:
  ```bash
  docker logs plant-disease-predictor
  ```
  Review the output for Python tracebacks or missing file errors, then correct the issue and rebuild.
