Docker images for developing and running Symfony web applications.
base: base image for Symfony applications, ready for production usagedev: image for development of Symfony applications, containing:- Symfony installer
- Composer
php-dbg, custom command line wrapper for debugging in PhpStormphp-prof, custom command line wrapper for generating XDebug profiling snapshots (Cachegrind)
The version schema reflects the PHP version used as the runtime environment.
The images include Nginx configurations adjusted to work for the PHP / Symfony applications they will contain. This approach was chosen in order to use a generic Nginx image. It works in Docker Compose environments, but may fail in Docker Swarm environments (untested) because of its distributed nature (no startup order, volume sharing).
A major drawback of this approach: when updating the configuration file you need to stop and remove the connected services in order to re-write the upated configuration file to the exchange volume.
How it works:
For an example please view the docker-compose.override.yml.dist of the dev flavour.
- define a volume
app-nginxto exchange the Nginx configuration file for the runtime environment (PHP, Symfony) - this volume is mounted to the
appservice, which will then distribute the shipped configuration file on startup to that volume - this volume is also mounted to the
nginxservice, effectively closing the exchange circle - the
nginxservice is marked as being dependent on theappservice to ensure the file is written before mounting the volume for itself
Tested with GNU Make 3.81. FLAVOUR environment variable defaults to base.
> make versions-avail
< 7.0/
make build -e VERSION=x.y [FLAVOUR=base|dev]
make release -e VERSION=x.y [FLAVOUR=base|dev]
Please note: the Docker image dreadlabs/php-symfony:x.y-dev MUST only be used in development contexts. To allow
access to Symfony's app_dev.php front controller, it will populate the custom FastCGI parameter X_ALLOW_DEBUG with
the value yes to the php-fpm/FastCGI server.
You should adjust the app_dev.php the following way in order to grant access in the context of this setup:
Default:
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !(in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1')) || php_sapi_name() === 'cli-server')
) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
New:
if (!(@$_SERVER['X_ALLOW_DEBUG'] === 'yes')
&& (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !(in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1')) || php_sapi_name() === 'cli-server'))
) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
The setup was tested with PhpStorm 2017.2.4. Please have a look at the following screenshots and setup your IDE accordingly.
No deployment setup is necessary for debugging.
Note: I left out the upper part "Pre-Configuration" as it serves informational purposes only.
No special configuration here. If I remember correctly, these settings match the standard configuration for new PHP projects.
Some tutorials mentioned to configure this in a certain way. But this is not necessary if you're not going to use a DBGp Proxy.
This part is very important to be matched against the PHP_IDE_CONFIG setting within the container.
Create a new configuration, named app. Set up the path mappings accordingly. In this example, I created a project, containing
multiple applications (api, auth, ...). The directory api contains a Symfony application. In most cases, the contents of
this directory will reside in the root of the PhpStorm project.
Map the application's root directory to /app and additionally (may be not necessary) map the application's web directory
to /app/web.
In order to run (^ R) or debug (^ D) the application on demand, I suggest to create a configuration for it:
Select from menu Run / Edit configurations. Hit the upper left +-Icon and select PHP Web Application.
First, setup PhpStorm according to: How to setup debugging for the dev flavour?.
Then click on the icon named "Start Listening for PHP Debug Connections". To run the application console with
debugging capabilities, simply prefix the app/console command with php-dbg:
php-dbg app/console
First, setup PhpStorm according to: How to setup debugging for the dev flavour?.
Then run:
php-prof app/console
The snapshot is stored in /tmp in the running Docker container.
- Xdebug is currently only working on Docker for Mac 17.06+
- see Discovering Docker’s IP Address for probably universal Docker host name/IP resolving




