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

3.1 KiB

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

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

3. Run Database Migrations

docker-compose exec app php artisan migrate

4. Seed Database (if needed)

docker-compose exec app php artisan db:seed

Useful Commands

View Container Logs

docker-compose logs -f app

Access Container Shell

docker-compose exec app bash

Stop Containers

docker-compose down

Stop and Remove Volumes (Clean Slate)

docker-compose down -v

Rebuild Containers

docker-compose up -d --build --force-recreate

Run Artisan Commands

docker-compose exec app php artisan [command]

Clear Laravel Cache

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

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:

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:

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:

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:

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.