This approach works with slight modifications works for most PHP web applications.
All containers should be treated as read-only unless is stated otherwise. Used patterns:
- one service per container
- Data Volume Container
Such separation allows for building and orchestrating using composer meta information ie.: determining PHP version, necessary extensions etc.
Servers as storage of all necessary source codes and pre-built assets using directory structure from Nette Sandbox.
It is just an example, you should build your own image, just don't forget to put everything in /nette
.
For passing arguments to application via environment variables you can use rixxi/env but be sure to know its limitations.
Your app/config/config.local.neon
should be either empty file or setup using environment variables.
env:
whitelist: no # allow all environment variables without listing them
doctrine:
host: %env.MYSQL_PORT_3006_TCP_ADDR%:%env.MYSQL_PORT_3006_TCP_PORT%
TIP: Your doctrine proxies should be already generated in temp.
Web server with basic php-fpm configuration.
- Server name
- SSL settings (optional)
- Application for static assets.
- Server for execution.
For execution of /nette/www/index.php.
- Server name
- Application specific configuration
- Application for code.
- Persistent Storage (optional) for cache, data and optionally sessions.
Simplifies configuration, backups, recoveries and lot of other stuff.
Simplifies erasing of cache and separates it from rest of the data.
Application should be in app container in /nette
directory with document root in www
.
Cache is exporting /nette/temp/cache
directory and journal file /nette/temp/dfjr.bin
.
Data is exporting /nette/data
.
Runs server with app and persistent storage at localhost:8080.
docker run --name project.cache rixxi/cache
docker run --name project.data rixxi/data
Either build containers locally or pull them from registry.
docker pull project/app
docker pull rixxi/php-fpm
docker pull rixxi/nginx
# remove garbage left from crashes
docker rm -f project.app
docker rm -f project.php-fpm
docker rm -f project.nginx
# application - data volume container
docker run -d project/app \
project.app
# php-fpm server
docker run -d rixxi/php-fpm \
--env 'SERVER_NAME=foo.bar' \
--volumes-from project.app:app:ro \
--volumes-from project.data \
--volumes-from project.cache \
project.php-fpm
# server
docker run -d rixxi/nginx \
--publish 80:80 \
--env 'SERVER_NAME=foo.bar' \
--link project.php-fpm:php-fpm \
--volumes-from project.app:ro \
project.nginx
Mount app /nette to directory with app code and build assets manually. If you need to debug data, mount persistent storage to local directory too.
docker run -d -v vendor/app --volume ~/dev/vendor/package:/nette vendor.app