Composer Php Docker



These image extends webdevops/php with a nginx daemon which is running on port 80 and 443

Uses Supervisord

This image is using supervisor and runs the daemon under user application (UID 1000; GID 1000) as default. If the container isstarted under a different user the daemon will be run under the specified uid.

3 - Re-build your PHP-FPM Container docker-compose build php-fpm. 4 - Check enabled locales with docker-compose exec php-fpm locale -a. Update the locale setting, default is POSIX. 1 - Open the.env file and set PHPFPMDEFAULTLOCALE to enUS.UTF8 or other locale you want. 2 - Re-build your PHP-FPM Container docker-compose build php-fpm. RUN rm -rf vendor && composer install FROM richarvey/nginx-php-fpm WORKDIR /var/www/html COPY -from=composer /app. This solution works and does not bloat the final image, but it is not ideal, because the vendor directory on the host is copied into the Docker context during the build process, which adds time. First, I need to install PHP and Composer to initiate the Symfony project. Sudo apt install php php-xml php-zip unzip. Php-xml and php-zip are requiert to install Symfony, unzip is recommended. Needs php and composer (or php composer.phar). Installing via Docker # Installing via Docker. The Docker community maintains WordPress and WP-CLI images.

Docker image tags¶

In this article, we will learn how to set up the Laravel development environment with Docker. We are going to use the Docker Compose to set up the development environment. Let’s start the steps without delay. This may also help: Laravel, Nginx and MySQL configuration with Docker Compose Video Tutorial Step 1 – Download Laravel Containerize your Laravel Application with Docker Compose.

TagDistribution namePHP Version
5.6customized official php imagePHP 5.6
7.0customized official php imagePHP 7.0
7.1customized official php imagePHP 7.1
7.2customized official php imagePHP 7.2
7.3customized official php imagePHP 7.3
7.4customized official php imagePHP 7.4
7.1-alpinecustomized official php imagePHP 7.1
7.2-alpinecustomized official php imagePHP 7.2
7.3-alpinecustomized official php imagePHP 7.3
7.4-alpinecustomized official php imagePHP 7.4
alpinedeprecatedPHP 7.x
alpine-php7deprecatedPHP 7.x
alpine-php5deprecatedPHP 5.6
alpine-3deprecatedPHP 5.6
alpine-3-php7deprecatedPHP 7.x
ubuntu-12.04deprecatedPHP 5.3
ubuntu-14.04deprecatedPHP 5.5
ubuntu-15.04deprecatedPHP 5.6
ubuntu-15.10deprecatedPHP 5.6
ubuntu-16.04deprecatedPHP 7.0
debian-7deprecatedPHP 5.4
debian-8deprecatedPHP 5.6
debian-8-php7deprecatedPHP 7.x (via sury)
debian-9deprecatedPHP 7.0
centos-7PHP 5.4
centos-7-php56PHP 5.6
centos-7-php7PHP 7.0

Environment variables¶

Base environment variables¶

Environment variableDescriptionDefault
LOG_STDOUTDestination of daemon outputempty (stdout)
LOG_STDERRDestination of daemon errorsempty (stdout)
SERVICE_CRON_OPTScron daemon argumentsempty (when syslog is used)
SERVICE_DNSMASQ_OPTSdnsmasq daemon argumentsempty (when syslog is used)
SERVICE_DNSMASQ_USERdnsmasq effective userroot
SERVICE_POSTFIX_OPTSpostfix daemon argumentsempty (when syslog is used)
SERVICE_SSH_OPTSssh daemon argumentsempty (when syslog is used)
SERVICE_SUPERVISOR_OPTSsupervisor daemon argumentsempty (when syslog is used)
SERVICE_SUPERVISOR_USERsupervisor effective userroot
SERVICE_SYSLOG_OPTSsyslog daemon argumentsempty (when syslog is used)

Base environment variables¶

Environment variableDescriptionDefault
POSTFIX_MYNETWORKSPostfix mynetworks addressempty
POSTFIX_RELAYHOSTPostfix upstream relay serverempty

Web environment variables¶

Docker Composer Php Version

Environment variableDescriptionDefault
WEB_DOCUMENT_ROOTDocument root for webserver/app
WEB_DOCUMENT_INDEXIndex documentindex.php
WEB_ALIAS_DOMAINDomain aliases*.vm
WEB_PHP_SOCKETPHP-FPM socket address127.0.0.1:9000 (for php-* images)
SERVICE_PHPFPM_OPTSPHP-FPM command argumentsempty (when php fpm is used)
SERVICE_APACHE_OPTSApache command argumentsempty (when apache is used)
SERVICE_NGINX_OPTSNginx command argumentsempty (when nginx is used)
SERVICE_NGINX_CLIENT_MAX_BODY_SIZENginx client_max_body_size50m (when nginx is used)

PHP modules¶

As we build our images containing almost every PHP module and having it activated by default, you might want to deactivate some.

You can specify a comma-separated list of unwanted modules as dynamic env variable PHP_DISMOD, e.g. PHP_DISMOD=ioncube,redis.

PHP.ini variables¶

You can specify eg. php.memory_limit=256M as dynamic env variable which will set memory_limit=256M as php setting.

Environment variableDescriptionDefault
php.{setting-key}Sets the {setting-key} as php setting
PHP_DATE_TIMEZONEdate.timezoneUTC
PHP_DISPLAY_ERRORSdisplay_errors0
PHP_MEMORY_LIMITmemory_limit512M
PHP_MAX_EXECUTION_TIMEmax_execution_time300
PHP_POST_MAX_SIZEpost_max_size50M
PHP_UPLOAD_MAX_FILESIZEupload_max_filesize50M
PHP_OPCACHE_MEMORY_CONSUMPTIONopcache.memory_consumption256
PHP_OPCACHE_MAX_ACCELERATED_FILESopcache.max_accelerated_files7963
PHP_OPCACHE_VALIDATE_TIMESTAMPSopcache.validate_timestampsdefault
PHP_OPCACHE_REVALIDATE_FREQopcache.revalidate_freqdefault
PHP_OPCACHE_INTERNED_STRINGS_BUFFERopcache.interned_strings_buffer16

PHP FPM variables¶

You can specify eg. fpm.pool.pm.max_requests=1000 as dyanmic env variable which will sets pm.max_requests=1000 as fpm pool setting.The prefix fpm.pool is for pool settings and fpm.global for global master process settings.

Environment variableDescriptionDefault
fpm.global.{setting-key}Sets the {setting-key} as fpm globalsetting for the master process
fpm.pool.{setting-key}Sets the {setting-key} as fpm poolsetting
FPM_PROCESS_MAXprocess.maxdistributiondefault
FPM_PM_MAX_CHILDRENpm.max_childrendistributiondefault
FPM_PM_START_SERVERSpm.start_serversdistributiondefault
FPM_PM_MIN_SPARE_SERVERSpm.min_spare_serversdistributiondefault
FPM_PM_MAX_SPARE_SERVERSpm.max_spare_serversdistributiondefault
FPM_PROCESS_IDLE_TIMEOUTpm.process_idle_timeoutdistributiondefault
FPM_MAX_REQUESTSpm.max_requestsdistributiondefault
FPM_REQUEST_TERMINATE_TIMEOUTrequest_terminate_timeoutdistributiondefault
FPM_RLIMIT_FILESrlimit_filesdistributiondefault
FPM_RLIMIT_CORErlimit_coredistributiondefault

Composer¶

Due to the incompatibilities between composer v1 and v2 we introduce a simple mechanism to switch between composer versions.

Environment variableDescriptionDefault
COMPOSER_VERSIONSpecify the composer version to use2

Be aware that this switch is only executed during container start (entrypoint).If you want to build your software with a specific composer version, you can do this:

Or composer respectively.

Customization¶

PHP customization¶

For customization a placeholder /opt/docker/etc/php/php.ini is available which will be loaded as lastconfiguration file. All settings can be overwritten in this ini file.

Either use COPY inside your Dockerfile to overwrite this file or useRUNechomemory_limit=128M>>/opt/docker/etc/php/php.ini to set specific php.ini values.

Nginx customization¶

This image has two directories for configuration files which will be automatic loaded.

Dockerfile

Composer Php Dockerfile

For global configuration options the directory /opt/docker/etc/nginx/conf.d can be used.For vhost configuration options the directory /opt/docker/etc/nginx/vhost.common.conf can be used.

Composer Php Dockery

Any *.conf files inside these direcories will be included either global or the vhost section.

Docker image layout¶

Nginx layout¶

File/DirectoryDescription
/opt/docker/etc/nginx/conf.d

Main global configuration directory

(automatically included files)

/opt/docker/etc/nginx/conf.d/10-php.confPHP cgi configuration
/opt/docker/etc/nginx/ssl

SSL configuration directory for

certifications and keys

/opt/docker/etc/nginx/ssl/server.crtExample SSL certification (*.vm)
/opt/docker/etc/nginx/ssl/server.csrExample SSL certification request (*.vm)
/opt/docker/etc/nginx/ssl/server.keyExample SSL key (*.vm)
/opt/docker/etc/nginx/vhost.common.d

Vhost configuration directory

(automatically included files)

/opt/docker/etc/nginx/vhost.common.d/10-location-root.confRedirect requests to DOCUMENT_INDEX
/opt/docker/etc/nginx/vhost.common.d/10-php.confPHP cgi configuration for vhost
/opt/docker/etc/nginx/global.confGlobal nginx configuration
/opt/docker/etc/nginx/main.confMain Nginx configuration
/opt/docker/etc/nginx/php.confDeprecated PHP configuration
/opt/docker/etc/nginx/vhost.common.confDeprecated vhost common include
/opt/docker/etc/nginx/vhost.confVhost configuration
/opt/docker/etc/nginx/vhost.ssl.confVhost SSL configuration
/opt/docker/etc/supervisor.d/nginx.confSupervisord configuration file for Nginx

PHP layout¶

File/DirectoryDescription
/opt/docker/etc/php/php.webdevops.iniPHP settings from WebDevOps image
/opt/docker/etc/php/php.iniphp.ini for custom settings
/opt/docker/etc/php/fpm/php-fpm.confPHP-FPM main configuration file
/opt/docker/etc/php/fpm/pool.d/application.confApplication PHP-FPM pool configuration file
/opt/docker/etc/supervisor.d/php-fpm.confSupervisord configuration file for PHP-FPM