BUT WHAT ABOUT PUPPET|ANSIBLE|CHEF|SALT? • Docker does not replace configuration management tools • These tools can in fact be used to provision docker platforms and/or containers themselves
CONTAINER GOTCHAS • Not a VM! • There is no init process, *your* process is PID 1 instead • No reaping, no cron, no services • Zombies! • Security implications, isolation is not complete
SHOULDN'T THIS BE AUTOMATED? • It's called Dockerfile • Defines all build steps • Build and tag (not push) in a single command • Cache results to speed up consecutive builds
docker build [OPTIONS] PATH ! -‐-‐force-‐rm=false Remove intermediate containers -‐-‐no-‐cache=false Do not use cache when building -‐q, -‐-‐quiet=false Suppress verbose output -‐-‐rm=true Remove intermediate containers -‐t, -‐-‐tag="" Repository name and tag DOCKERFILE
HANDS ON • We need a container running PHP-CLI • For simplicity, a global phpunit.phar install • We need a workdir to define where we will run our tests later • Tag as registry.dockerworkshop.dev/ phpunit:php55
HANDS ON • Build another phpunit container • This time, running PHP 5.3.x • (Yes, 5.3) • Hint: There is a ubuntu:12.04 in the registry • Tag as registry.dockerworkshop.dev/ phpunit:php53
NICE, BUT… • Isolated, throw-away, testing environments! • We still have a dedicated config on the CI side, because it needs to know about specifics (like the container names)
INTRODUCING FUGU • Written in Go • Utility to preconfigure docker run & build commands • For single containers • A single, simple YAML file • Allows us to configure our tests a bit similar to Travis (right in our project)
IDEAS • Build a complete single container with DB and fixtures and run Behat • Build separate DB containers with different fixtures • If a test fails, push the resulting container to a registry for further analysis • …
HANDS ON: PHP • Base: our Nginx container • Install PHP Packages and supervisord • Download and install composer • Replace webroot, Nginx config, index.html • Set CMD to supervisor • Tag and push
CONNECTING • The PHP container needs to now where to find the DB • Solution: Links • Create environment variables with network info • Add entries to /etc/hosts
HANDS ON • Run the PHP container interactively and check out the /etc/hosts file • Modify the database connection code in src/app.php line 27 to use the new hostname