Best practices talk on how to containerize, test and run an application using (Docker) containers. Presented at TYPO3 camp Venlo, the Netherlands. Note that slides are mainly meant as a summary of the talk.
process feels at home • Also a pretty lonely (isolated) place. • It all starts with an image (distro + libraries + runtime + default config) • If your run an image it becomes a container (like class → object) • Can have dependencies like config, storage, networking
are easy to extend • Less abstraction, back to shell commands • Consistency between dev/test/prod • Predictable! • Almost no overhead → fast • There are many tools! • Force automating everything • Suited for Web/Desktop/CLI apps
somewhere else) • Running (persistent) databases in a container is still a challenge • That said databases are probably the most stable part of a typical app Are there disadvantages too?
images (stand on the shoulders of giants) • Take a look around at hub.docker.com • Be aware of unoffical (cowboy) images • Use specific versions of base images. • Keep images small in size • Optimize layers...when your done. • Think about readability • Update often (scheduled builds)
does too much • Consider splitting app • Containers are perfect for m(icro/ini/edium) services. • Pack image and application together for production • Docker has many more best practices on their website!
Mount persistent files (database, uploads) • Mount local config/cache (composer, npm) • Separate application and build tools • Run tools as yourself (uid/gid) • Helper scripts for containerized tools • log to stdout
(xdebug, composer etc.) • Leave out crap (tests, documentation, dev related config) • Mount persistent files like uploads • Do not keep state (that you can't rebuild) • Consider running a container as read only • Containerized database? → do research first • Run as non root user • Use health checks • Spend time on setting up logging
• You can run all build tools in a container • Even docker-compose runs in a container • Minimum: Docker engine + Make or bash • Build production assets
different containers: Httpd/Runtime/Db/Cache/Queue • Different runtimes in different containers: PHP/Nodejs • Different helper concerns in different containers: Gulp (watch), Mailcatcher, Selenium
PHP example: • Base: PHP + libs + exts • Dev: base + xdebug + env vars + mount • Build: base + composer + zip + git + mount • Prod: base + copy of built application