This Docker configuration sets up a PHP 8.4 environment optimized for running Symfony applications. It includes RoadRunner as the HTTP server, integrates Composer for PHP dependencies, and builds frontend assets using NodeJS.
This Dockerfile leverages a multi-stage build to efficiently build and serve a production-ready Symfony app:
- PHP 8.4 Alpine: Lightweight PHP environment with essential extensions.
- RoadRunner 2025: High-performance HTTP server.
- NodeJS 22 Alpine: For compiling JavaScript assets.
- Docker (v24+ recommended)
- Docker Compose (optional, recommended for development convenience)
| Component | Version | 
|---|---|
| PHP | 8.4 Alpine | 
| Composer | v2 (latest) | 
| RoadRunner | 2025 | 
| NodeJS | 22 Alpine | 
- opcache
- zip
- intl
- sockets
- protobuf
- pdo_pgsql
- redis
(Extensions like mbstring and curl are included by default.)
/app
│
├── public/
│   └── build/ (compiled frontend assets)
├── var/
│   ├── cache/
│   └── log/
├── vendor/ (composer dependencies)
├── composer.json
├── webpack.config.js
├── package.json
├── server.sh (entrypoint script)
└── assets/ (source frontend files, excluded from final image)
This script optimizes and prepares the application runtime environment by:
- Dumping environment-specific variables (composer dump-env prod).
- Clearing and warming up Symfony cache.
- Running Doctrine database migrations.
- Starting the RoadRunner server.
#!/bin/bash
# Optimizing application before start
composer dump-env prod
php bin/console cache:clear --no-interaction
php bin/console cache:warmup --no-interaction
php bin/console doctrine:migrations:migrate --no-interaction
./rr serve -c .rr.yamlThe .dockerignore file optimizes build performance and maintains image cleanliness by excluding files such as:
/.env.local
/.env.local.php
/.env.*.local
/config/secrets/prod/prod.decrypt.private.php
/public/bundles/
/public/build/
/var/
/vendor/
/phpunit.xml
.phpunit.result.cache
/.idea/
/node_modules/
npm-debug.log
yarn-error.logdocker build -t symfony-app .docker run -p 8080:8080 -d symfony-appThe application will be accessible at http://localhost:8080.
Default environment variables provided by the Dockerfile:
- APP_ENV=prod
- APP_DEBUG=0
These settings are suitable for production deployments.
- Modify server.shto customize RoadRunner startup logic or add additional startup routines.
- Adjust the .dockerignorefile if additional files or directories must be excluded.
- Customize webpack.config.jsaccording to your frontend build requirements.
- Stage 1 (server): Sets up PHP environment, including Composer, PHP extensions, and RoadRunner.
- Stage 2 (node_build): Installs NodeJS dependencies and builds frontend assets.
- Stage 3 (final): Integrates the compiled frontend assets back into the PHP/RoadRunner environment, producing a streamlined, optimized runtime container.
The Dockerfile explicitly creates a non-root user (app) to enhance security by running the application with minimal privileges. Directories such as /app, var/cache, and var/log are secured with appropriate permissions (700) and ownership (app:app).
For issues, enhancements, or contributions, please open a GitHub issue or pull request, clearly stating the proposed changes.