5. The Apache stack
Apache + PHP:
custom build image with Apache, mod_php and
SSH access
Mysql:
official Mysql or Mariadb image listening on port
3306 using volumes from data container
Memcached:
official image with memory limitation listening on
port 11211
Mysql
Apache-PHP
Memcached
Mysql Data
6. The Nginx stack
Nginx:
official Docker image listening on port 80
and using fastcgi for PHP-FPM
Mysql:
official Mysql or Mariadb image listening on port
3306 using volumes from data container
Memcached:
official image with memory limitation listening on
port 11211
PHP-FPM:
custom build image with PHP-FPM and SSH access
Mysql
Nginx
PHP-FPM
Memcached
Mysql Data
7. The PHP image
Custom build image based on phusion/baseimage:
• Ubuntu 14.04 LTS
• Easy to use init system
• Syslog and logrotate configured correctly
• Crond
• Ondrej Sury PPA repository
Running services:
• Postfix
• Syslogd
• Crond
• PHP-FPM or Apache
Different images for:
• PHP 5.5, 5.6 or 7.0
• PHP-FPM or Apache with mod_php
• With or without development tools
8. The PHP development image
A layer on top of the PHP image to add functionality
for development environment like:
• SSH server
• Xdebug
• Custom entrypoint.sh to create user on first boot
• Various development tools
Development tools:
• Phing
• Phpcs
• Phpmd
• Phpunit
• Bower
• Grunt
• Gulp
• Npm
9. Container access
• Using SSH to access the container using agent
forwarding
• The same username and userid as the host OS is
available inside the container to preserve
ownership and permissions
• Optimized Bash prompt and installed all required
tools for development
• All sudo rights available when needed
Entrypoint.sh
A small script set as entrypoint that creates a new
user on first boot of the container using environment
variables.
This makes sure that the user on the host OS is
available inside the container with the same
username and userid.
10. Linked volume
The /var/www volume is shared with the host
OS.
● Directly linked from the host OS
● No need for continuously syncing during
development
● State between container lifecycles remain
• /var/www/
• .ssh/
• sites/
• my-application/
• web/
• .bash_history
• .bashrc
• .gitconfig
11. Container linking
Using container linking to enable DNS aliases
inside containers.
In this way the DNS alias can used inside your
app configuration.
● The mysql and memcached containers are
linked to the PHP container and are available
as hostname “mysql” and “memcached”.
● The PHP container is linked to Nginx and is
available as hostname “php”.
# parameters.yml
parameters:
database_host: mysql
memcached_host: memcached
# nginx.conf
server {
location ~ .php(/|$) {
fastcgi_pass php:9000;
}
}
12. Virtualhost configuration
Configuration for Nginx/Apache is
stored outside the container so it easy
to add virtualhosts for each application.
The default virtualhost resolves all
domain names to document root:
./www/sites/<domain>/web
# apache.conf
<Virtualhost *:80>
ServerName sites.dev
DirectoryIndex index.html index.php app.php
VirtualDocumentRoot /var/www/sites/%1/web
</Virtualhost>
# nginx.conf
server {
server_name ~^(?<domain>.+).dev$;
root /var/www/sites/$domain/web;
}
13. DNS aliases
Solutions:
• Use static ip address
• Use dnsmasq for wildcard
subdomains like *.dev
• Add each hostname to
/etc/hosts
# /etc/dnsmasq.conf
address=/dev/192.168.99.100
# /etc/hosts
192.168.99.100 application.dev
15. Resources
PHP docker images
https://github.com/yoshz/docker-php
https://hub.docker.com/u/yoshz/
Bunch of dockerfiles to can build different types of
PHP containers.
- PHP 5.5, 5.6 or 7.0
- Apache + mod_php or Nginx + php-fpm
- Separate images with development tools
integrated
PHP Development Stack
https://github.com/yoshz/phpdevstack
Bunch of scripts and docker-compose files to quickly
start your own development stack with PHP.