Skip to content

Latest commit

 

History

History
336 lines (248 loc) · 12.3 KB

File metadata and controls

336 lines (248 loc) · 12.3 KB

SaaS Bot Platform — Docker Setup

What We're Containerizing

Container Purpose
app Laravel PHP application
nginx Web server
db PostgreSQL database
redis Queue & cache

Project Folder Structure

koshai-lagbe/
├── docker/
│   ├── nginx/
│   │   └── default.conf
│   └── php/
│       └── Dockerfile
├── src/                  ← Your Laravel app lives here
├── docker-compose.yml
└── .env.docker

Step 1 — PHP Dockerfile

File: docker/php/Dockerfile

FROM php:8.3-fpm

RUN apt-get update && apt-get install -y \
    git curl libpng-dev libonig-dev libxml2-dev \
    libzip-dev zip unzip \
    && apt-get clean && rm -rf /var/lib/apt/lists/*

RUN docker-php-ext-install \
    pdo_mysql mbstring exif pcntl bcmath gd zip opcache

RUN pecl install redis && docker-php-ext-enable redis

COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

WORKDIR /var/www
RUN chown -R www-data:www-data /var/www

EXPOSE 9000
CMD ["php-fpm"]

Step 2 — Nginx Config

File: docker/nginx/default.conf

server {
    listen 80;
    index index.php index.html;
    root /var/www/public;

    client_max_body_size 20M;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        fastcgi_pass app:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

Step 4 — Docker Compose

File: docker-compose.yml

version: '3.8'

services:

  app:
    build:
      context: .
      dockerfile: docker/php/Dockerfile
    container_name: koshai-lagbe_app
    restart: unless-stopped
    working_dir: /var/www
    volumes:
      - ./src:/var/www
    networks:
      - koshai-lagbe_network
    depends_on:
      - db

  nginx:
    image: nginx:alpine
    container_name: koshai-lagbe_nginx
    restart: unless-stopped
    ports:
      - "8000:80"
    volumes:
      - ./src:/var/www
      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
    networks:
      - koshai-lagbe_network
    depends_on:
      - app

  db:
    image: postgres:18
    container_name: koshai-lagbe_db
    volumes:
      - ./src:/var/www
      - ./docker/db/initdb.d:/docker-entrypoint-initdb.d
      - pg_data:/var/lib/postgresql
    environment:
      POSTGRES_DB: ${DB_DATABASE}
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_PASSWORD: ${DB_PASSWORD}
    ports:
      - "15732:5432"
    restart: unless-stopped
    networks:
      - koshai-lagbe_network

networks:
  koshai-lagbe_network:
    driver: bridge

volumes:
  pg_data:

Step 5 — Environment File

File: .env.docker

DB_DATABASE=saas_bot
DB_USERNAME=saas_user
DB_PASSWORD=secret123

Step 6 — Create the Laravel App

composer create-project laravel/laravel src

Then update src/.env:

APP_NAME="Koshai Lagbe"
APP_ENV=local
APP_DEBUG=true
APP_URL=http://localhost:8000

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=saas_bot
DB_USERNAME=saas_user
DB_PASSWORD=secret123

CACHE_DRIVER=redis
QUEUE_CONNECTION=redis
SESSION_DRIVER=redis

REDIS_HOST=redis
REDIS_PORT=6379

DB_HOST=mysql and REDIS_HOST=redis point to Docker service names, not localhost.


Step 7 — Build and Start

cp .env.docker .env
docker-compose up -d --build

Wait 60–90 seconds, then:

docker exec koshai-lagbe_app composer install
docker exec koshai-lagbe_app php artisan key:generate
docker exec koshai-lagbe_app php artisan migrate

Step 8 — Pull Ollama Model

# Recommended — fast and lightweight
docker exec koshai-lagbe_ollama ollama pull llama3.2:3b

# If RAM is limited (under 8GB)
docker exec koshai-lagbe_ollama ollama pull llama3.2:1b

The model is stored in the ollama_data volume. You only do this once.


Step 9 — Testing

Run each test in order. All must pass before moving to Part 2.

Test 1 — All containers running

docker ps

Expected: 7 containers all showing Up


Test 2 — Laravel is reachable

Open: http://localhost:8000

Expected: Laravel welcome page loads


Test 3 — phpMyAdmin is reachable

Open: http://localhost:8080

Expected: phpMyAdmin login/dashboard loads


Test 4 — Database connection

docker exec koshai-lagbe_app php artisan migrate:status

Expected: Migration table listed, no errors


Test 5 — Redis connection

docker exec koshai-lagbe_app php artisan tinker
Cache::put('test', 'working', 10);
Cache::get('test');

Expected: Returns "working"


Test 6 — Queue worker is running

docker logs koshai-lagbe_queue

Expected: Processing jobs from the [default] queue


Test 7 — Full queue round trip

Inside tinker:

dispatch(function() {
    \Log::info('Queue is working');
});

Then:

docker logs koshai-lagbe_queue

Expected: Queue is working appears in logs


Common Problems & Fixes

Problem Fix
Port 8000 already in use Change "8000:80" to "8080:80" in docker-compose
PostgreSQL connection refused Wait 30 more seconds, PostgreSQL takes time to initialize
Permission denied on storage docker exec koshai-lagbe_app chmod -R 775 storage bootstrap/cache

Quick Reference Commands

# Start everything
docker-compose up -d

# Stop everything
docker-compose down

# Restart one service
docker-compose restart app

# View logs
docker logs koshai-lagbe_app

# Enter the app container shell
docker exec -it koshai-lagbe_app bash

# Clear Laravel caches
docker exec koshai-lagbe_app php artisan optimize:clear

Access Points

Service URL
Laravel App http://localhost:8000