docker set up added

This commit is contained in:
erishBRBS 2025-04-29 08:19:31 +08:00
parent d49b0ff407
commit a65f3aeae4
17 changed files with 149 additions and 0 deletions

0
bootstrap/app.php Normal file → Executable file
View File

0
bootstrap/cache/.gitignore vendored Normal file → Executable file
View File

0
bootstrap/providers.php Normal file → Executable file
View File

67
docker-compose.yml Normal file
View File

@ -0,0 +1,67 @@
services:
app:
build:
context: .
dockerfile: ./docker/php/Dockerfile
container_name: unioil-app
restart: unless-stopped
volumes:
- .:/var/www/html
- ./storage:/var/www/html/storage
- ./bootstrap/cache:/var/www/html/bootstrap/cache
depends_on:
db_mysql:
condition: service_healthy
command:
[ "sh", "-c", "/var/www/html/docker/php/entrypoint.sh" ]
healthcheck:
test: ["CMD", "pgrep", "php-fpm"]
interval: 30s
timeout: 10s
retries: 10
networks:
- app_network
db_mysql:
image: mysql:8.2
container_name: unioil-db
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: laravel
MYSQL_DATABASE: unioil_cms
MYSQL_USER: admin_erish
MYSQL_PASSWORD: Laravel@123
volumes:
- mysql-data:/var/lib/mysql
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 30s
timeout: 10s
retries: 5
networks:
- app_network
nginx:
image: nginx:alpine
container_name: unioil-nginx
restart: unless-stopped
ports:
- "8000:80"
volumes:
- .:/var/www/html
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
depends_on:
app:
condition: service_healthy
networks:
- app_network
volumes:
mysql-data:
storage-volume:
driver: local
networks:
app_network:
driver: bridge

25
docker/nginx/default.conf Normal file
View File

@ -0,0 +1,25 @@
server {
listen 80;
server_name localhost;
root /var/www/html/public;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass app:9000; # laravel app container
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
}

29
docker/php/Dockerfile Normal file
View File

@ -0,0 +1,29 @@
# Base image
FROM php:8.3-fpm-alpine
# Install required PHP extensions
RUN docker-php-ext-install pdo pdo_mysql bcmath
# Install Composer
COPY --from=composer:2.7 /usr/bin/composer /usr/bin/composer
# Install Node.js and npm
RUN apk add --no-cache nodejs npm
# Set working directory
WORKDIR /var/www/html
# Copy app files
COPY . /var/www/html
# Ensure entrypoint script is executable
RUN chmod +x /var/www/html/docker/php/entrypoint.sh
# Set permissions for app files
RUN chown -R www-data:www-data /var/www/html
# Expose PHP-FPM port
EXPOSE 9000
# Start PHP-FPM (handled in entrypoint.sh)
CMD ["sh", "-c", "/var/www/html/docker/php/entrypoint.sh"]

28
docker/php/entrypoint.sh Executable file
View File

@ -0,0 +1,28 @@
#!/bin/sh
# Exit script on any error
set -e
# Ensure we're in the right directory
cd /var/www/html
# Install PHP dependencies
composer install --no-dev --optimize-autoloader
# Install Node.js dependencies if node_modules not present
if [ ! -d "node_modules" ]; then
npm install
fi
# Build frontend assets
npm run build
# Set correct permissions for storage and cache
chown -R www-data:www-data storage bootstrap/cache
chmod -R 775 storage bootstrap/
# Run database migrations
php artisan migrate --force
# Start PHP-FPM
php-fpm

0
storage/app/.gitignore vendored Normal file → Executable file
View File

0
storage/app/private/.gitignore vendored Normal file → Executable file
View File

0
storage/app/public/.gitignore vendored Normal file → Executable file
View File

0
storage/framework/.gitignore vendored Normal file → Executable file
View File

0
storage/framework/cache/.gitignore vendored Normal file → Executable file
View File

0
storage/framework/cache/data/.gitignore vendored Normal file → Executable file
View File

0
storage/framework/sessions/.gitignore vendored Normal file → Executable file
View File

0
storage/framework/testing/.gitignore vendored Normal file → Executable file
View File

0
storage/framework/views/.gitignore vendored Normal file → Executable file
View File

0
storage/logs/.gitignore vendored Normal file → Executable file
View File