This Dockerfile creates an optimized PHP-FPM image for the OSIRIS application. It uses a multi-stage build process to minimize the resulting image size and improve build efficiency.
- Base Image: PHP 8.1 with FPM on Alpine Linux
- PHP Extensions:
- LDAP
- ZIP
- MongoDB
- Author: Paul C. Gaida
The Dockerfile implements a two-stage build process:
-
Composer Stage:
- Installs Composer and PHP dependencies
- Uses only the necessary files (
composer.jsonandcomposer.lock) - Optimized for better caching and faster builds
-
Main Stage:
- Installs necessary system packages and PHP extensions
- Copies the vendor files installed in the first stage
- Copies the application code and sets up permissions
-
System Packages:
- openldap-dev (for LDAP support)
- libzip-dev (for ZIP support)
- openssl-dev (for secure connections)
- autoconf, gcc, g++, make (build tools for extension compilation)
-
PHP Extensions:
- ldap (for LDAP authentication)
- zip (for ZIP file handling)
- mongodb (for MongoDB database connections)
- Docker installed on the host system
- The OSIRIS source files in the current directory
docker build -t osiris:latest .docker run -d --name osiris-app -p 9000:9000 osiris:latestTo use the application with a web server, connect it to the PHP-FPM port 9000.
docker run -d --name osiris-app \
-p 9000:9000 \
-v $(pwd):/var/www/html \
osiris:latestStart development environment:
docker-compose -f docker-compose.dev.yml up -dStart production environment:
docker-compose -f docker-compose.prod.yml up -d- The
/var/www/html/imgdirectory has extended write permissions for thewww-datauser - Vendor dependencies are installed during the build and placed in the final image
- Only the PHP extensions necessary for the application are installed
To install additional PHP extensions, extend the docker-php-ext-install command:
RUN docker-php-ext-install ldap zip mysqli pdo_mysqlTo install additional PECL extensions:
RUN pecl install redis && docker-php-ext-enable redis