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.json
andcomposer.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:latest
To 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:latest
Create a docker-compose.yml
file:
version: '3'
services:
app:
build:
context: nginx
dockerfile: nginx/Dockerfile
volumes:
- ./img:/var/www/html/img
ports:
- "9000:9000"
web:
image: nginx:alpine
ports:
- "80:80"
volumes:
- ./:/var/www/html
- ./nginx.conf:/etc/nginx/conf.d/default.conf
depends_on:
- app
And start the services:
docker-compose up -d
- The image is optimized for production and contains no development tools
- The
/var/www/html/img
directory has extended write permissions for thewww-data
user - 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_mysql
To install additional PECL extensions:
RUN pecl install redis && docker-php-ext-enable redis