DOCKER_README.md 5.6 KB

Docker Containerization Guide

Overview

This inventory management system has been containerized with Docker for easy deployment and scaling. The setup includes:

  • Backend PHP service with Apache
  • Frontend Vue.js service with Nginx
  • MySQL database
  • Redis cache (optional)
  • External volume mounts for uploads

Quick Start

Prerequisites

  • Docker and Docker Compose installed
  • At least 2GB RAM available
  • Sufficient disk space for uploads

1. Environment Configuration

Copy the example environment file and customize it:

cp .env.example .env

Edit the .env file with your specific configuration:

# Database Configuration
DB_HOST=mysql
DB_PORT=3306
DB_NAME=inventory_db
DB_USER=inventory_user
DB_PASS=your_secure_password
MYSQL_ROOT_PASSWORD=your_root_password

# Company Information
COMPANY_NAME=Your Company Name
COMPANY_ADDRESS=123 Business Street
COMPANY_CITY=Helsinki
COMPANY_POSTAL_CODE=00100
COMPANY_COUNTRY=Finland
COMPANY_PHONE=+358 123 456 789
COMPANY_EMAIL=info@yourcompany.com
COMPANY_Y_TUNNUS=1234567-8

# File Upload Configuration
UPLOAD_MAX_SIZE=10M
ALLOWED_FILE_TYPES=pdf,doc,docx,xls,xlsx,jpg,jpeg,png,gif
UPLOADS_PATH=./uploads

# Frontend Configuration
VUE_APP_API_URL=http://localhost:8080

2. Build and Start Containers

docker-compose up -d --build

3. Access the Application

Configuration Details

Environment Variables

Database Configuration

  • DB_HOST: Database server hostname (default: mysql)
  • DB_PORT: Database port (default: 3306)
  • DB_NAME: Database name (default: inventory_db)
  • DB_USER: Database username (default: inventory_user)
  • DB_PASS: Database password (required)
  • MYSQL_ROOT_PASSWORD: MySQL root password (required)

Company Information

  • COMPANY_NAME: Your company name
  • COMPANY_ADDRESS: Company address
  • COMPANY_CITY: Company city
  • COMPANY_POSTAL_CODE: Postal code
  • COMPANY_COUNTRY: Country
  • COMPANY_PHONE: Phone number
  • COMPANY_EMAIL: Email address
  • COMPANY_Y_TUNNUS: Finnish business ID

File Upload Configuration

  • UPLOAD_MAX_SIZE: Maximum file upload size (default: 10M)
  • ALLOWED_FILE_TYPES: Allowed file extensions
  • UPLOADS_PATH: External path for uploads volume mount

Frontend Configuration

  • VUE_APP_API_URL: Backend API URL for frontend

Volume Mounts

Uploads Directory

The uploads directory is mounted as an external volume to persist file uploads across container restarts:

volumes:
  uploads_data:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: ${UPLOADS_PATH:-./uploads}

Database Data

MySQL data is persisted in a Docker volume:

volumes:
  mysql_data:
    driver: local

Network Configuration

All services communicate through a dedicated Docker network:

networks:
  inventory-network:
    driver: bridge

Production Deployment

Security Considerations

  1. Change all default passwords
  2. Use HTTPS in production (configure SSL certificates)
  3. Restrict database access to internal network only
  4. Regularly update containers and dependencies
  5. Implement proper backup strategy for database and uploads

Scaling

The architecture supports horizontal scaling:

  • Frontend can be scaled by adding more Nginx containers behind a load balancer
  • Backend can be scaled by adding more PHP containers
  • Database can be moved to external managed service

Monitoring

Consider adding:

  • Health checks for all services
  • Log aggregation
  • Performance monitoring
  • Backup automation

Development

Local Development

For development, you can run services individually:

# Start only database
docker-compose up -d mysql

# Start backend with live reload
docker-compose up -d --build backend

# Start frontend with live reload
cd frontend && npm run serve

Debugging

View logs for specific services:

# Backend logs
docker-compose logs -f backend

# Frontend logs
docker-compose logs -f frontend

# Database logs
docker-compose logs -f mysql

Database Management

Connect to the database:

docker-compose exec mysql mysql -u inventory_user -p inventory_db

Troubleshooting

Common Issues

Database Connection Failed

  1. Check if MySQL container is running: docker-compose ps
  2. Verify database credentials in .env file
  3. Check database logs: docker-compose logs mysql

Upload Directory Not Working

  1. Ensure uploads directory exists on host
  2. Check permissions: ls -la uploads/
  3. Verify volume mount in docker-compose.yml

Frontend Not Loading

  1. Check if backend is accessible: curl http://localhost:8080/api/company.php
  2. Verify API URL configuration
  3. Check frontend logs: docker-compose logs frontend

Performance Optimization

  1. Enable Redis caching for frequently accessed data
  2. Configure PHP OPcache for better performance
  3. Use CDN for static assets
  4. Implement database connection pooling

Maintenance

Updates

To update the application:

# Pull latest changes
git pull

# Rebuild and restart containers
docker-compose down
docker-compose up -d --build

Backups

Regular backups should include:

  1. Database dump: docker-compose exec mysql mysqldump -u root -p inventory_db
  2. Uploads directory: tar -czf uploads_backup.tar.gz uploads/

Cleanup

Remove unused containers and images:

docker system prune -a
docker volume prune

Support

For issues and questions, refer to the application logs or contact your system administrator.