This guide explains how to deploy the complete inventory management system using Docker and Docker Compose with two deployment options.
Perfect for production environments with existing database infrastructure.
git clone <repository-url>
cd inventory
# Copy and edit environment file
cp backend/.env.local backend/.env.local
nano backend/.env.local
Configure your external database:
DB_HOST=your-external-db-host
DB_PORT=3306
DB_NAME=inventory_db
DB_USER=your-username
DB_PASS=your-password
docker-compose up -d
Perfect for development, testing, or all-in-one deployments.
git clone <repository-url>
cd inventory
docker-compose -f docker-compose-with-services.yml --env-file .env.with-services up -d
inventory_user / inventory_passwordroot / root_passwordredis_passwordSingle container solution that includes:
Multi-container solution that includes:
Persistent Volumes: Database, Redis, and uploads storage
inventory-app (single container)
โโโ Apache Web Server
โโโ PHP Backend (/var/www/html/api)
โโโ Vue.js Frontend (/var/www/html/frontend/dist)
โโโ Uploads (/var/www/html/uploads)
โโโ External Database Connection
inventory-app (main container)
โโโ Apache Web Server
โโโ PHP Backend (/var/www/html/api)
โโโ Vue.js Frontend (/var/www/html/frontend/dist)
โโโ Uploads (/var/www/html/uploads)
inventory-mariadb (database container)
โโโ MariaDB 10.11
โโโ Auto-initialized Database
โโโ Persistent Storage
inventory-redis (cache container)
โโโ Redis 7
โโโ Password Protected
โโโ Persistent Storage
# Database Configuration (External)
DB_HOST=your-external-db-host
DB_PORT=3306
DB_NAME=inventory_db
DB_USER=your-db-username
DB_PASS=your-db-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
# Database Configuration (Built-in)
DB_HOST=mariadb
DB_PORT=3306
DB_NAME=inventory_db
DB_USER=inventory_user
DB_PASS=inventory_password
MYSQL_ROOT_PASSWORD=root_password
# Redis Configuration (Built-in)
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_PASSWORD=redis_password
# Frontend Configuration
FRONTEND_PORT=80
MARIADB_PORT=3306
REDIS_PORT=6379
# 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
## ๐ ๏ธ Docker Compose Services
### inventory-app
- **Purpose**: Main application container
- **Image**: Built from Dockerfile
- **Ports**: 80:80
- **Features**: PHP backend + Vue.js frontend
- **Database**: Connects to external database via environment variables
### redis (optional)
- **Purpose**: Caching layer
- **Image**: redis:7-alpine
- **Ports**: 6379:6379
- **Volume**: Persistent data storage
## ๐๏ธ External Database Setup
### Database Requirements
- **MySQL 8.0+** or **MariaDB 10.5+**
- **Network Access**: Container must be able to reach database host
- **Schema**: Run `backend/migrate_complete.sql` to create database schema
- **Permissions**: User needs CREATE, SELECT, INSERT, UPDATE, DELETE privileges
### Database Setup Steps
bash
mysql -u root -p -e "CREATE DATABASE inventory_db;"
mysql -u root -p -e "CREATE USER 'inventory_db'@'%' IDENTIFIED BY 'your_password';"
mysql -u root -p -e "GRANT ALL PRIVILEGES ON inventory_db.* TO 'inventory_db'@'%';"
mysql -u inventory_db -p inventory_db < backend/migrate_complete.sql
mysql -u root -p -e "FLUSH PRIVILEGES;"
## ๐ File Structure
inventory/ โโโ Dockerfile # Multi-stage build (Node.js + PHP) โโโ docker-compose.yml # Container orchestration โโโ docker/ โ โโโ apache.conf # Apache configuration โโโ backend/ โ โโโ api/ # PHP API endpoints โ โโโ config/ # Configuration files โ โโโ models/ # PHP models โ โโโ migrate_complete.sql # Database schema (for external DB) โโโ frontend/ โ โโโ src/ # Vue.js source code โ โโโ dist/ # Built frontend (generated) โ โโโ package.json # Node.js dependencies โโโ uploads/ # File upload directory โโโ .env.example # Environment template โโโ .env # Environment configuration โโโ build.sh # Build script
## ๐ง Management Commands
### Start Application
bash docker-compose up -d
### Stop Application
bash docker-compose down
### View Logs
bash
docker-compose logs
docker-compose logs inventory-app docker-compose logs db docker-compose logs redis
docker-compose logs -f inventory-app
### Rebuild Application
bash
docker-compose build --no-cache
docker-compose build inventory-app
### Database Management
bash
mysql -h your-external-db-host -u your-db-username -p inventory_db
mysqldump -h your-external-db-host -u your-db-username inventory_db > backup.sql
mysql -h your-external-db-host -u your-db-username inventory_db < backup.sql
docker-compose exec inventory-app php -r "echo 'Testing DB connection...';"
### Container Management
bash
docker-compose ps
docker-compose exec inventory-app bash
docker-compose restart inventory-app
docker-compose down
docker-compose up -d
## ๐จ Troubleshooting
### Common Issues
#### 1. Database Connection Failed
bash
docker-compose logs inventory-app
docker-compose exec inventory-app ping your-external-db-host
docker-compose exec inventory-app php -r " try {
\$pdo = new PDO('mysql:host=your-external-db-host;dbname=inventory_db', 'your-db-username', 'your-db-password');
echo 'Database connection successful';
} catch (Exception \$e) {
echo 'Database connection failed: ' . \$e->getMessage();
} "
mysql -h your-external-db-host -u your-db-username -p inventory_db -e "SHOW TABLES;"
#### 2. Frontend Not Loading
bash
docker-compose logs inventory-app
docker-compose build --no-cache inventory-app
docker-compose exec inventory-app apache2ctl -M
#### 3. File Upload Issues
bash
docker-compose exec inventory-app ls -la /var/www/html/uploads
docker-compose exec inventory-app chown -R www-data:www-data /var/www/html/uploads docker-compose exec inventory-app chmod -R 755 /var/www/html/uploads
#### 4. API Not Responding
bash
curl http://localhost/api/company.php
docker-compose exec inventory-app service apache2 status
docker-compose exec inventory-app service apache2 restart
### Health Checks
The application includes health checks:
- **inventory-app**: Tests `/api/company.php` endpoint
- **redis**: Tests Redis connectivity (optional)
View health status:
bash docker-compose ps
## ๐ Security Considerations
### Production Deployment
1. **Change Default Passwords**: Update database passwords in .env
2. **Use HTTPS**: Configure SSL/TLS termination
3. **Network Isolation**: Use custom networks
4. **Resource Limits**: Set memory and CPU limits
5. **Regular Updates**: Keep Docker images updated
### Environment Security
bash
chmod 600 .env
echo "DB_PASSWORD=your_secure_password" > .env.secret
## ๐ Performance Optimization
### Production Optimizations
1. **Enable Redis Caching**: Configure Redis for session storage
2. **Database Optimization**: Use persistent connections
3. **Frontend Caching**: Enable browser caching
4. **Load Balancing**: Use multiple containers behind a load balancer
### Monitoring
bash
docker stats
docker-compose exec inventory-app df -h
docker-compose exec inventory-app free -m
## ๐ Updates and Maintenance
### Updating Application
bash
git pull
docker-compose build --no-cache docker-compose up -d
docker-compose exec db mysql -u inventory_db inventory_db < migration.sql
### Backup Strategy
bash
docker-compose exec db mysqldump -u inventory_db inventorydb > backup$(date +%Y%m%d).sql
tar -czf uploads_$(date +%Y%m%d).tar.gz uploads/
cp .env .env.backup ```
For issues with the Docker deployment:
docker-compose logsYour inventory management system is now running in Docker with: