Files
merchbay_admin/README-DOCKER.md
2025-12-12 01:06:06 +08:00

166 lines
3.1 KiB
Markdown

# Docker Deployment Guide for MerchBay Admin
## Prerequisites
- Docker installed on your system
- Docker Compose installed on your system
## Quick Start
### 1. Build and Start Containers
```bash
docker-compose up -d --build
```
This will:
- Build the application container
- Start MySQL database
- Start PHPMyAdmin
- Set up networking between containers
### 2. Access the Application
- **Application**: http://localhost:8080
- **PHPMyAdmin**: http://localhost:8081
### 3. Run Database Migrations
```bash
docker-compose exec app php artisan migrate
```
### 4. Seed Database (if needed)
```bash
docker-compose exec app php artisan db:seed
```
## Useful Commands
### View Container Logs
```bash
docker-compose logs -f app
```
### Access Container Shell
```bash
docker-compose exec app bash
```
### Stop Containers
```bash
docker-compose down
```
### Stop and Remove Volumes (Clean Slate)
```bash
docker-compose down -v
```
### Rebuild Containers
```bash
docker-compose up -d --build --force-recreate
```
### Run Artisan Commands
```bash
docker-compose exec app php artisan [command]
```
### Clear Laravel Cache
```bash
docker-compose exec app php artisan cache:clear
docker-compose exec app php artisan config:clear
docker-compose exec app php artisan route:clear
docker-compose exec app php artisan view:clear
```
### Install/Update Composer Dependencies
```bash
docker-compose exec app composer install
# or
docker-compose exec app composer update
```
## Environment Configuration
Edit the `docker-compose.yml` file to customize:
- Database credentials
- Port mappings
- Environment variables
For production deployment, update the `APP_ENV` and `APP_DEBUG` values:
```yaml
environment:
- APP_ENV=production
- APP_DEBUG=false
```
## Database Connection
The application connects to the MySQL container using these credentials (defined in docker-compose.yml):
- **Host**: db
- **Database**: merchbay_admin
- **Username**: merchbay_user
- **Password**: merchbay_password
## Troubleshooting
### Permission Issues
If you encounter permission errors:
```bash
docker-compose exec app chown -R www-data:www-data /var/www/html/storage
docker-compose exec app chmod -R 755 /var/www/html/storage
```
### Database Connection Issues
Ensure the database container is fully started:
```bash
docker-compose logs db
```
Wait a few seconds after starting containers for MySQL to initialize.
### Port Already in Use
If ports 8080 or 3306 are already in use, modify the ports in `docker-compose.yml`:
```yaml
ports:
- "8090:80" # Change 8080 to 8090 or any available port
```
## Production Deployment
For production environments:
1. Update `.env` file with production settings
2. Set `APP_DEBUG=false` in docker-compose.yml
3. Use a secure database password
4. Consider using a reverse proxy (Nginx/Traefik) with SSL
5. Set up proper backup strategies for database volumes
6. Configure log rotation
## Volumes
- `db_data`: Persistent MySQL data
- `./storage`: Laravel storage (logs, cache, sessions)
- `./public/uploads`: User uploaded files
These volumes ensure data persists across container restarts.