Deployment Guide
Deploying to production (Docker, Kubernetes, serverless)
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.
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 pointrequirements.txt— all Python dependenciesconfig.toml— Streamlit configuration filecredentials.toml— Streamlit credentials fileDockerfile— provided in the project root
- Network access to pull the
python:3.10-slimbase image from Docker Hub - Port
80available and open on your host machine or cloud firewall rules
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.
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.
docker build -t plant-disease-predictor .
Docker will:
- Pull the
python:3.10-slimbase image. - Copy your project files into the
/appdirectory inside the container. - Install all dependencies listed in
requirements.txt. - Copy your Streamlit configuration files into the container's home directory.
- Expose port
80for HTTP traffic.
Step 3 — Run the container
Start the container and map port 80 inside the container to port 80 on your host:
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.
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:
# 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:
[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.
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
- Navigate to
http://your-server-address(orhttp://localhostfor local testing). - Use the file upload widget on the main page to select a leaf image from your device.
- Supported formats are those accepted by the CNN model (typically
.jpg,.jpeg, and.png). - 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:
docker run -d -p 80:80 --name plant-disease-predictor plant-disease-predictor
To check that it is still running:
docker ps
To stop the service:
docker stop plant-disease-predictor
Example 1 — Build and run for the first time
This is the complete sequence from a fresh clone to a running service.
# 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:
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:
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:
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
Use this section to diagnose and resolve the most common issues encountered during deployment.
Issue: Port 80 is already in use
- Symptom:
docker runfails with an error such asBind 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:
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 buildstep fails with aCOPYerror, such asCOPY failed: file not found in build context. - Likely cause: One or both configuration files are missing from your project root directory.
- Fix: Ensure
config.tomlandcredentials.tomlexist in the same directory as yourDockerfilebefore runningdocker build.
Issue: Application starts but browser shows a blank page or connection refused
- Symptom: Navigating to
http://localhostor your server IP returns no response or a blank page. - Likely cause:
headlessmode is not set totrueinconfig.toml, or the container's port mapping is incorrect. - Fix: Verify your
config.tomlcontainsheadless = trueunder[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.txtwith package resolution or network errors. - Likely cause: Missing or malformed
requirements.txt, or no internet access from the build host. - Fix: Confirm
requirements.txtis present and valid. If behind a corporate proxy, configure Docker's proxy settings before building.
Issue: Container exits immediately after starting
- Symptom:
docker psshows no running containers; the container appears briefly then stops. - Likely cause:
main.pycontains a startup error, or a required model file is missing from the image. - Fix: Inspect the logs immediately after the crash:
Review the output for Python tracebacks or missing file errors, then correct the issue and rebuild.
docker logs plant-disease-predictor