# docker/php/php.Dockerfile# Pull the composer imageFROM composer:latest as composer# Pull the PHP fpm imageFROM php:8.3-fpm# Set working directoryWORKDIR /var/www# Install dependenciesRUN apt-get update && apt-get install -y \ build-essential \ libpng-dev \ libonig-dev \ libxml2-dev \ zip \ curl \ unzip \ git \ libzip-dev \ libfreetype6-dev \ libjpeg62-turbo-dev \ libpng-dev \ libpq-dev \ && docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \ && docker-php-ext-install pdo pgsql pdo_pgsql pdo_mysql mbstring exif pcntl bcmath gd zip intl opcache# Clear cacheRUN apt-get clean && rm -rf /var/lib/apt/lists/*# Enable the following 2 commands if imagick extension is required# RUN apt-get update && apt-get install -y libmagickwand-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*# RUN mkdir -p /usr/src/php/ext/imagick; \# curl -fsSL https://github.com/Imagick/imagick/archive/06116aa24b76edaf6b1693198f79e6c295eda8a9.tar.gz | tar xvz -C "/usr/src/php/ext/imagick" --strip 1; \# docker-php-ext-install imagick;# Remove default server definitionRUN rm -rf /var/www/html# Install ComposerCOPY --from=composer /usr/bin/composer /usr/bin/composer# Copy existing application directory contentsCOPY . .# Install application dependenciesRUN composer install# Copy existing application directory contentsRUN chown -R www-data:www-data /var/www# Change current user to wwwUSER www-data# Expose port 9000 and start php-fpm serverEXPOSE 9000CMD ["php-fpm"]
# docker/nginx/nginx.confserver { listen 80; index index.php index.html; error_log /var/log/nginx/error.log; access_log /var/log/nginx/access.log; root /var/www/public; send_timeout 300s; proxy_read_timeout 300s; fastcgi_read_timeout 300s;location / { try_files $uri $uri/ /index.php?$query_string; }location~\.php$ { fastcgi_pass php:9000; #name of the sevice that runs the laravel app in docker-compose.yml file fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; }location~/\.ht { deny all; }}
# docker-compose.ymlservices:php:build:context:.dockerfile:./docker/php/php.Dockerfilecontainer_name:bigboxcode-phprestart:unless-stoppedworking_dir:/var/wwwvolumes:-./:/var/www-./.env:/var/www/.env-/var/www/vendorenvironment:-APP_ENV=developmentnetworks:-bigboxcode-networkdepends_on:-mysqlnginx:image:nginx:alpinecontainer_name:bigboxcode-nginxports:-8000:80volumes:-./:/var/www-./docker/nginx/log:/var/log/nginx-./docker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf:rodepends_on:-php-mysqlnetworks:-bigboxcode-networkmysql:image:mysql:8.0container_name:bigboxcode-mysqlports:-3306:3306volumes:-mysql_data:/var/lib/mysqlenvironment:MYSQL_DATABASE:bigboxcodeMYSQL_ROOT_PASSWORD:rootMYSQL_PASSWORD:bigboxpassMYSQL_USER:bigboxusernetworks:-bigboxcode-networknode:# platform: linux/arm64/v8 #this line is optional if you are using Mac Silicon chip (M1/M2/M3)build:context:.dockerfile:./docker/node/node.Dockerfilecontainer_name:bigboxcode-nodeports:# - 3000:3000-5173:5173restart:unless-stoppedworking_dir:/var/wwwvolumes:-./:/var/www-/var/www/node_modulesenvironment:-NODE_ENV=development# - CHOKIDAR_USEPOLLING=true # required for file change reflection# - CHOKIDAR_INTERVAL=3000networks:-bigboxcode-networkdepends_on:-phpvolumes:"mysql_data":networks:"bigboxcode-network":driver:bridge
Dockerize Laravel Application
# docker-compose.ymlservices:# ---- Other services(PHP, Nginx, MySQL) herenode:# platform: linux/arm64/v8 #this line is optional if you are using Mac Silicon chip (M1/M2/M3)build:context:.dockerfile:./docker/node/node.Dockerfilecontainer_name:bigboxcode-nodeports:# - 3000:3000-5173:5173restart:unless-stoppedworking_dir:/var/wwwvolumes:-./:/var/www-/var/www/node_modulesenvironment:-NODE_ENV=development# - CHOKIDAR_USEPOLLING=true # required for file change reflection# - CHOKIDAR_INTERVAL=3000networks:-bigboxcode-networkdepends_on:-php
# docker/node/node.Dockerfile# Set the base imageFROM node:latest# Set working directoryWORKDIR /var/www# Copy `package.json` and `package-lock.json`COPY package*.json ./# Install project dependenciesRUN npm install# Copy project files into the docker imageCOPY . .# Expose the port Vite runs onEXPOSE 3000# Start the Vite serverCMD ["npm", "run", "dev"]
# MakefilePHP_CONTAINER = bigboxcode-phpNODE_CONTAINER = bigboxcode-node# Run the applicationdefault: docker compose up# Build docker containers and prepare the environmentbuild: docker compose build --no-cache --progress=plain# Access PHP containeraccess-php: docker exec -it $(PHP_CONTAINER) sh# Run migration in the PHP containermigrate: docker exec -it $(PHP_CONTAINER) php artisan migrate# Sync vendor directory from PHP container to the hostvendor-sync: docker cp $(PHP_CONTAINER):/var/www/vendor ./# Sync node_modules directory from node container to the hostnode-modules-sync: docker cp $(NODE_CONTAINER):/var/www/node_modules ./