Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions docker/containers/composer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# Pull from PHP from previous Dockerfile - php/Dockerfile
# - use the image tag for php - php:php-<version>-fpm-alpine
# - see docker/docker-compose.yml for more info
FROM php:php-8.2-fpm-alpine
# CRITICAL FIX:
# The FROM instruction now uses the alias 'base'.
# This alias is defined in docker-compose.yml's 'additional_contexts'
# and explicitly tells Docker to use the result of the 'php' service build
# as the base image, fixing the build order dependency.
FROM base

# Install Composer
# This curl command fetches the installer and pipes it to PHP, installing the
# Composer executable (named 'composer') directly into /usr/local/bin.
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer --version=2.6.1

# Since the executable is in /usr/local/bin, it is automatically available in the container's PATH.
# Add composer bin path to environment variable
RUN export PATH=$PATH":/usr/bin"
22 changes: 15 additions & 7 deletions docker/containers/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
# Install PHP
# Start from the official base image
FROM php:8.2-fpm-alpine

# Copy PHP configuration
#COPY ./containers/php/config/php-$SYS_ENV-$HOST_SECRET.ini /usr/local/etc/php/php.ini
# Set the working directory to the standard web root
WORKDIR /var/www/html

# Install PHP Extension
RUN apk --no-cache add zip libzip-dev \
# Install common system dependencies and PHP extensions in a single layer
# 1. Install system packages (git, zip dependencies)
# 2. Configure and install required PHP extensions (opcache for speed)
RUN apk add --no-cache git zip libzip-dev \
&& docker-php-ext-configure zip \
&& docker-php-ext-install zip mysqli pdo pdo_mysql \
&& docker-php-ext-enable pdo_mysql \
&& docker-php-ext-install mysqli pdo pdo_mysql opcache zip \
&& rm -rf /var/cache/apk/* # Clean up cache to minimize image size

# Copy PHP configuration
# COPY ./containers/php/config/php-$SYS_ENV.ini /usr/local/etc/php/php.ini

# Default command to start PHP-FPM
CMD ["php-fpm"]
44 changes: 41 additions & 3 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
version: '3.8'
# Dockerize Web Development Template (DWDT)

# =====================================================================
# 1. NETWORKS
# =====================================================================
networks:
web-app:
# Explicitly names the network using the COMPOSE_PROJECT_NAME variable
name: ${COMPOSE_PROJECT_NAME}_app_net

# =====================================================================
# 2. SERVICES
# =====================================================================
services:
# +----------------------+ #
# | Container: NginX | #
Expand All @@ -21,6 +29,10 @@ services:
- "${PATH_CONFIGS_NGINX}:/etc/nginx/conf.d/default.conf"
- "${PATH_VOLUMES_LOGS}/nginx:/var/log/nginx"
- "${PATH_SOURCE_LOCAL}:${PATH_SOURCE_LIVE}"
# Vendor volume overlay
- vendor_data:/var/www/html/vendor
# Node Modules volume overlay
- node_modules_data:/var/www/html/node_modules
depends_on:
- php
- database
Expand Down Expand Up @@ -83,11 +95,18 @@ services:
build:
context: .
dockerfile: containers/composer/Dockerfile
# FIX: This crucial block forces the 'php' service to be built first,
# and makes the resulting image available to the composer Dockerfile
# under the alias 'base'.
additional_contexts:
base: service:php
image: composer:composer-2.6.1
working_dir: /var/www/html
volumes:
- "${PATH_CONFIGS_PHP}:/usr/local/etc/php/php.ini"
- "${PATH_SOURCE_LOCAL}:${PATH_SOURCE_LIVE}"
# CRITICAL: Composer installs dependencies directly into this fast volume
- vendor_data:/var/www/html/vendor
depends_on:
- php
entrypoint: ['composer']
Expand All @@ -103,10 +122,12 @@ services:
working_dir: /var/www/html
volumes:
- "${PATH_SOURCE_LOCAL}:${PATH_SOURCE_LIVE}"
# NEW: Overlays the node_modules directory with a fast Docker volume
- node_modules_data:/var/www/html/node_modules
depends_on:
- php
entrypoint: ['npm']
#

# # +----------------------+ #
# # | Container: Artisan | #
# # +----------------------+ #
Expand All @@ -117,7 +138,11 @@ services:
# build:
# context: .
# dockerfile: containers/php/Dockerfile
# image: artisan:laravel-9
# # FIX: This crucial block forces the 'php' service to be built first,
# # and makes the resulting image available to artisan container
# additional_contexts:
# base: service:php
# image: artisan:laravel-XXX # name it with whatever that makes sense for you
# links:
# - php
# - database
Expand All @@ -126,7 +151,20 @@ services:
# working_dir: /var/www/html
# volumes:
# - "${PATH_SOURCE_LOCAL}:${PATH_SOURCE_LIVE}"
# # Must include vendor data so Artisan can execute PHP dependencies
# - vendor_data:/var/www/html/vendor
# depends_on:
# - php
# - database
# entrypoint: ['php', '/var/www/html/artisan']

# =====================================================================
# 3. VOLUMES
# =====================================================================
volumes:
# Dedicated volume for Composer dependencies (vendor folder)
vendor_data:
driver: local
# Dedicated volume for NPM/Node dependencies (node_modules folder)
node_modules_data:
driver: local
1 change: 1 addition & 0 deletions docker/environments/config.env
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# SYSTEM VARIABLES
# values: local | test | prod
SYS_ENV=local
COMPOSE_PROJECT_NAME=my_web_app

# PATHS / DIRECTORIES / VOLUMES
PATH_CONTAINERS=./containers
Expand Down