Initial commit with Docker setup for Laravel, MySQL, and Nginx

This commit is contained in:
m.marjorie 2025-03-24 14:30:06 +08:00
parent 37b9d1380d
commit 88329c1206
2 changed files with 52 additions and 53 deletions

View File

@ -1,26 +1,31 @@
FROM php:8.2-fpm
# Install dependencies
RUN apt-get update && apt-get install -y \
libpng-dev \
libjpeg-dev \
libfreetype6-dev \
zip \
unzip \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install gd pdo pdo_mysql
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Set working directory
WORKDIR /var/www/html
# Install dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip
# Copy the application code
COPY . .
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Install Laravel dependencies
RUN composer install --no-dev --optimize-autoloader
# Set permissions
RUN chown -R www-data:www-data /var/www/html
RUN chown -R www-data:www-data /var/www/html/storage /var/www/html/bootstrap/cache
# Expose port
EXPOSE 9000
CMD ["php-fpm"]

View File

@ -1,70 +1,64 @@
version: '3.8'
services:
# MySQL Database
db:
mysql:
image: mysql:8.0
container_name: laravel-mysql
restart: unless-stopped
container_name: mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: laravel
MYSQL_ROOT_PASSWORD: root_password
MYSQL_USER: laravel_user
MYSQL_PASSWORD: laravel_password
MYSQL_USER: laravel
MYSQL_PASSWORD: secret
volumes:
- mysql_data:/var/lib/mysql
ports:
- "3306:3306"
- mysql-data:/var/lib/mysql
networks:
- laravel-network
- app-network
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
restart: unless-stopped
# Laravel Application
app:
laravel:
build:
context: .
dockerfile: Dockerfile
container_name: laravel-app
restart: unless-stopped
volumes:
- ./src:/var/www/html
container_name: laravel
depends_on:
db:
mysql:
condition: service_healthy
volumes:
- .:/var/www/html
networks:
- laravel-network
- app-network
healthcheck:
test: ["CMD", "php", "-v"]
test: ["CMD", "php", "artisan", "config:cache"]
interval: 10s
timeout: 5s
retries: 5
command: >
sh -c "php-fpm"
# Nginx Web Server
web:
image: nginx:alpine
container_name: laravel-nginx
sh -c "php artisan migrate --force && php-fpm"
restart: unless-stopped
nginx:
image: nginx:alpine
container_name: nginx
depends_on:
laravel:
condition: service_healthy
ports:
- "80:80"
volumes:
- ./src:/var/www/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
app:
condition: service_healthy
- ./nginx.conf:/etc/nginx/conf.d/default.conf
- .:/var/www/html
networks:
- laravel-network
- app-network
restart: unless-stopped
networks:
laravel-network:
app-network:
driver: bridge
volumes:
mysql_data:
mysql-data: