version: '3.8'
services:
app:
build:
context: .
dockerfile: Dockerfile
container_name: laravel_app
volumes:
- .:/var/www/html
- ./docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
environment:
APP_ENV: ${APP_ENV:-production}
APP_DEBUG: ${APP_DEBUG:-false}
APP_KEY: ${APP_KEY:-base64:khjKjdiNDdnYYcPLMkjenmkhKjShdOyd}
APP_URL: ${APP_URL:-http://localhost}
DB_CONNECTION: mysql
DB_HOST: mariadb
DB_PORT: 3306
DB_DATABASE: ${DB_DATABASE:-laravel}
DB_USERNAME: ${DB_USERNAME:-root}
DB_PASSWORD: ${DB_PASSWORD:-secret}
REDIS_HOST: redis
REDIS_PASSWORD: ${REDIS_PASSWORD:-null}
REDIS_PORT: ${REDIS_PORT:-6379}
depends_on:
- mariadb
- redis
ports:
- 8000:80
mariadb:
image: mariadb
container_name: laravel_mariadb
volumes:
- ./docker/mariadb/data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD:-secret}
MYSQL_DATABASE: ${DB_DATABASE:-laravel}
MYSQL_USER: ${DB_USERNAME:-root}
MYSQL_PASSWORD: ${DB_PASSWORD:-secret}
redis:
image: redis:alpine
container_name: laravel_redis
volumes:
- ./docker/redis/data:/data
File Dockerfile
FROM php:8.2-fpm
# Install required PHP extensions
RUN docker-php-ext-install pdo_mysql
RUN docker-php-ext-install pdo_mysql bcmath ctype fileinfo json mbstring opcache tokenizer xml
RUN pecl install redis && docker-php-ext-enable redis
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Set working directory
WORKDIR /var/www/html
# Copy Laravel application files to working directory
COPY . .
# Install Laravel dependencies
RUN composer install --no-interaction --prefer-dist --optimize-autoloader
# Set file permissions
RUN chown -R www-data:www-data /var/www/html/storage /var/www/html/bootstrap/cache
# Expose port 9000 for Swoole
EXPOSE 9000
# Start PHP-FPM and keep it running
CMD ["php-fpm"]
Sau khi tạo file docker-compose.yml, bạn có thể chạy container bằng lệnh docker-compose up -d. Chạy lệnh này trong thư mục chứa file docker-compose.yml. Lệnh -d cho phép container chạy ở chế độ daemon. Để dừng container, bạn có thể chạy lệnh docker-compose down.
Nhận xét
Đăng nhận xét