Skip to content

akayumeru/Symfony-RoadRunner-NodeJS-Docker-Example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Docker Setup for PHP 8.4 & Symfony Application with RoadRunner and NodeJS Assets

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.

Overview

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.

Prerequisites

  • Docker (v24+ recommended)
  • Docker Compose (optional, recommended for development convenience)

Included Components

Component Version
PHP 8.4 Alpine
Composer v2 (latest)
RoadRunner 2025
NodeJS 22 Alpine

PHP Extensions Installed

  • opcache
  • zip
  • intl
  • sockets
  • protobuf
  • pdo_pgsql
  • redis

(Extensions like mbstring and curl are included by default.)


Directory Structure

/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)

Entrypoint (server.sh)

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.yaml

Excluded Files (.dockerignore)

The .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.log

How to Build and Run

1. Build the Docker Image

docker build -t symfony-app .

2. Run the Docker Container

docker run -p 8080:8080 -d symfony-app

The application will be accessible at http://localhost:8080.


Environment Variables

Default environment variables provided by the Dockerfile:

  • APP_ENV=prod
  • APP_DEBUG=0

These settings are suitable for production deployments.


Customization and Further Steps

  • Modify server.sh to customize RoadRunner startup logic or add additional startup routines.
  • Adjust the .dockerignore file if additional files or directories must be excluded.
  • Customize webpack.config.js according to your frontend build requirements.

Docker Multi-stage Build Explained

  • 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.

Security and Permissions

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).


Support and Contribution

For issues, enhancements, or contributions, please open a GitHub issue or pull request, clearly stating the proposed changes.

About

Docker Setup for PHP 8.4 & Symfony Application with RoadRunner and NodeJS Assets

Topics

Resources

Stars

Watchers

Forks