Skip to main content
Deploy the entire Predictive Maintenance System stack (backend + frontend) using Docker containers for consistent, portable deployment across environments.

Prerequisites

Never commit node_modules/ to Git. Windows binaries cause permission errors on Linux servers (Vercel Error 126).
Ensure you have installed:
  • Docker Engine 20.10+
  • Docker Compose V2+
  • Git

Quick Start

1

Clone the repository

git clone https://github.com/BhaveshBytess/PREDICTIVE-MAINTENANCE.git
cd PREDICTIVE-MAINTENANCE
2

Start all services

Launch both backend and frontend containers:
docker-compose up --build
For background execution:
docker-compose up -d
3

Access the application

Once started, access:

Docker Compose Configuration

The docker-compose.yml defines two main services:

Backend Service

backend:
  build:
    context: ./backend
    dockerfile: Dockerfile
  container_name: pm_backend
  restart: unless-stopped
  ports:
    - "8000:8000"
  env_file:
    - ./backend/.env
  environment:
    - ENVIRONMENT=local
  healthcheck:
    test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')"]
    interval: 30s
    timeout: 10s
    retries: 3
    start_period: 10s
Key features:
  • restart: unless-stopped - Auto-restarts on failure
  • Health checks every 30 seconds
  • Environment variables loaded from backend/.env
  • Exposed on port 8000

Frontend Service

frontend:
  build:
    context: ./frontend
    dockerfile: Dockerfile
    args:
      - VITE_API_URL=http://localhost:8000
  container_name: pm_frontend
  restart: unless-stopped
  ports:
    - "5173:80"
  depends_on:
    - backend
Key features:
  • Multi-stage build with nginx
  • Depends on backend service
  • Production-optimized React build
  • Exposed on port 5173 (mapped to internal port 80)

Environment Configuration

1

Backend environment

Create backend/.env from the example:
cp backend/.env.example backend/.env
Configure your InfluxDB connection:
# Environment
ENVIRONMENT=local

# API Configuration
API_V1_STR=/api/v1
PROJECT_NAME=Predictive Maintenance

# InfluxDB Configuration
INFLUX_URL=http://localhost:8086
INFLUX_TOKEN=your-influxdb-token-here
INFLUX_ORG=your-organization
INFLUX_BUCKET=sensor_data
2

Frontend environment (optional)

Create frontend/.env.local if needed:
cp frontend/.env.example frontend/.env.local
# API Configuration
VITE_API_URL=http://localhost:8000
For Docker deployment, the API URL is passed as a build argument in docker-compose.yml, so this file is optional.

Docker Commands Reference

Service Management

docker-compose up -d

Monitoring and Logs

docker-compose logs -f

Container Management

docker-compose exec backend bash

Optional: Local InfluxDB

For complete isolation, run InfluxDB locally instead of using InfluxDB Cloud:
1

Uncomment InfluxDB service

Edit docker-compose.yml and uncomment the InfluxDB section:
influxdb:
  image: influxdb:2.7-alpine
  container_name: pm_influxdb
  restart: unless-stopped
  ports:
    - "8086:8086"
  environment:
    - DOCKER_INFLUXDB_INIT_MODE=setup
    - DOCKER_INFLUXDB_INIT_USERNAME=admin
    - DOCKER_INFLUXDB_INIT_PASSWORD=adminpassword
    - DOCKER_INFLUXDB_INIT_ORG=predictive_maintenance
    - DOCKER_INFLUXDB_INIT_BUCKET=sensor_data
    - DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=my-super-secret-token
  volumes:
    - influxdb_data:/var/lib/influxdb2
Also uncomment the volumes section:
volumes:
  influxdb_data:
2

Update backend environment

Modify backend/.env to connect to the local InfluxDB:
INFLUX_URL=http://influxdb:8086
INFLUX_TOKEN=my-super-secret-token
INFLUX_ORG=predictive_maintenance
INFLUX_BUCKET=sensor_data
3

Restart services

docker-compose down
docker-compose up -d
Access InfluxDB UI at http://localhost:8086

Troubleshooting

Port Already in Use

Problem: Error port is already allocated Solution: Change the port mapping in docker-compose.yml:
ports:
  - "8001:8000"  # Changed from 8000:8000

Backend Health Check Failing

Problem: Container repeatedly restarting Solution: Check logs and verify InfluxDB connection:
docker-compose logs backend
Verify environment variables:
docker-compose exec backend env | grep INFLUX

Build Failures

Problem: Error response from daemon: failed to build Solution: Clear Docker cache and rebuild:
docker-compose down
docker system prune -a
docker-compose up --build

Cannot Connect to Backend from Frontend

Problem: API requests failing in browser Solution: Ensure services are on the same network. Check with:
docker network inspect predictive-maintenance_default
For browser access, use http://localhost:8000, not the container name.

Production Considerations

Docker Compose is designed for development and testing. For production deployments, use:
  • Backend: Render, Railway, or AWS ECS
  • Frontend: Vercel, Netlify, or Cloudflare Pages
  • Database: InfluxDB Cloud
See Production Deployment for details.

Security Hardening

For production-like local deployment:
  1. Use secrets management:
    docker secret create influx_token /path/to/token
    
  2. Enable TLS: Add nginx reverse proxy with Let’s Encrypt certificates
  3. Limit container resources:
    deploy:
      resources:
        limits:
          cpus: '0.5'
          memory: 512M
    
  4. Use specific image tags (not latest):
    image: influxdb:2.7.1-alpine
    

Next Steps

Build docs developers (and LLMs) love