Con$nuous Deployment with Docker Andrew Aslinger Oct 9. 2014
Who is Andrew #1 So#ware / Systems Architect for OpenWhere Passion for UX, Big Data, and Cloud/DevOps Previously Designed and Implemented automated DevOps processes for several organiza@ons Mul$ple environments, many user / developer groups, big data clusters, hundreds of machines A Recovering Chef
Who is Andrew #2 (Andy) Host of AWS DC Meet Up Started as a developer who could talk to opera@ons and infrastructure teams Lived the transi@on from data center, Co- Lo, internal cloud, to AWS To much fun to ever go back
Agenda What is Docker? Con$nuous Delivery with AWS and Docker Docker Advanced Prac$ces and Lessons Learned Demo & Discussion 4
What is Docker? Docker is an open pla/orm for developers and sysadmins to build, ship, and run distributed applica:ons Yet another DevOps tool light weight container Latest hype?
Docker Benefits Virtual Machines Portability Across Machines Local Vagrant like deployment, Remote Deployment including Amazon EC2 Independent of host OS Lightweight vs VMs Supports DevOps Best Prac@ces & Re- use Infrastructure as Code Container Extensibility Docker Fits into a Con@nuous Deployment Pipeline Isola@on and Single Responsibility Reduce dependency conflicts, security
A Typical Docker Flow with six simple commands Docker Registry registryname: https://registry.hub.docker.com/ or Private registry Development Environment Host Environment docker tag imagename registryname/ imagename Docker Image docker build t imagename. Docker Image Docker Container docker run p 9000:9000 d --name containername imagename docker stop/restart/start containername Dockerfile conf 7
OpenWhere DevOps Philosophy 1. Immutable Infrastructure Focus on one process (build) vs. two (build & maintain) 2. Simplify the Tools Minimize On- boarding & Training Minimize Tools 3. Purpose Built Environments 4. DevOps code should co- exist with applica@on code How to build infrastructure for project inline with project Jenkins scripts Docker 5. Auto- scale from start
Why Docker with EC2? Build once, run many places Dev Machines, different clouds, different VPCs, share and build Not $ed to box size or guest OS AMI s are difficult to rebuild and more difficult to maintain Snapshots retain baggage There is no git version control for AMI AMI s are not cross region compa$ble Other AMI tools like Amiator aren t easy to use Easier to achieve immutable infrastructure and one click deploys Maintaining machines sucks Treat your infrastructure as code with a Con@nuous Deployment Pipeline
Why Docker with EC2? Separate your data and state from your image Machine layers evolve at different velocity and have different reuse (Example Later) Core OS Organiza$on Level Requirements Applica$on Level Requirements Applica$on Code Test and version control your deploy ar$facts and configura$on together Same container for developers and EC2 Java Example Stop maintaining AMIs +
Docker Con@nuous Deployment Flow: Set up AWS infrastructure 1 Create AWS Ec2 Instances and install Docker yum install -y docker-io service docker start.
Docker Con@nuous Deployment Flow: Build and push docker image with latest code 6 Push new Image to public or private repo 4 Push Artifacts (optional) 5 Build new Docker Image from Docker File 3 SCM Poll Trigger build 2 Commit New Code w/ Docker file
Docker Con@nuous Deployment Flow: Trigger EC2 to pull latest Docker image 8 Docker Pull & start container 7 Trigger Docker Pull on target machines
Advanced #1: Docker Image Layers using FROM and OnBuild commands in the Docker File Docker Image Layers ONBUILD Project Code Specific Image Organiza$on Applica$on Image (Example NodeJs Web App Image) Organiza$on Base OS Jenkins Built Reusable Project SCM Application Dependencies & Config: NodeJS, express, supervisord etc. Common Dependencies & Config: Security, LDAP, Logging, etc. Core OS Base OS: CentOs, Ubuntu, etc. Machine layers can evolve at different velocity and have different levels of reuse
Advanced #2: Linked Containers Run multiple containers on a machine. Each with a responsibility linked by ports / address https://docs.docker.com/userguide/dockerlinks/ --link name:alias docker run -d -P --name web --link db:db training/webapp python app.py Container 1 DB Container 2 Web $DB_PORT = 6379, etc. /etc/hosts db 172.0.0.2 Host OS
Advanced #3: Data Containers A container which allows sharing of data across containers https://docs.docker.com/userguide/dockervolumes/ Benefits: Change image independent of data (maintainability) Enables Data sharing patterns (single responsibility) Limitations: Data is Tied to Host OS sudo docker run -d --volumes-from dbdata --name db2 training/postgres Data Container (non running) /volume -file1.txt -file2.txt /volume Container 2 Web Container 3 Web /volume Physical files docker managed Host OS
Advanced #4: Customize on Init You need to parameterize and modify items in a container based on the environment Examples: Set a IP address or DNS name, Set a DB password Pattern: 1. Load a script onto the box as part of an building the image 2. Run script at container launch 3. Script uses environment variables to customize settings files etc 4. Environment variables are passed to the docker run Command docker run -e DB=10.0.0.1 start.sh Data Container (non running) sed config.conf Service Discovery & Registra$on is an emerging area
OpenWhere Docker Wins 1. Full con@nuous deployment and write once, deploy many @mes realized 2. Developer Replacement for vagrant Less complexity Test with what you deploy! 3. Deployment build process co- exists with the so#ware! Reduced Maintenance, developer buy- in, testability 4. Awesome Re- use with minimal code 1 line Dockerfile(s) for new MEAN Stack apps 5. Simplicity (Streamlined DevOps)
OpenWhere Docker Burns Learning Curve / Maturity Learning a Docker way for each DevOps task (s$ll in progress) Example: Need tricks to do things like have more than one process running in a container Example: Learning layers are independent and don t retain state between RUN commands A Docker Container is not the same as a typical virtual machine Basic stuff like syslog off and tar, wget not installed Base Image: hmp://phusion.github.io/baseimage- docker/ Containers not restar@ng on EC2 Restart We hacked a cloud- init work around Upda@ng to new images is dirty Manually clean up images / containers or run out of disk! Debugging more complex: You can only a`ach to a Docker container if the program you are running is a shell Install SSH or we have a workaround trick
Recommenda$ons Docker works great for a Con$nuous Deployment flow on EC2 Especially for stateless applica$ons or a micro- service architecture Complex cluster deployments, stateful applica$ons or databases, service discovery etc. not quite there yet You may need to roll your own solu$on or integrate with another technology
Ques$ons
Contact Informa$on Andrew Aslinger Senior Systems Architect OpenWhere aaslinger@openwhere.com @aaa572 hmp://owaaa.github.io/ Andrew Heifetz Chief Cloud Officer OpenWhere aheifetz@openwhere.com @andyheifetz hmp://www.linkedin.com/pub/andrew- heifetz Cell: 240-481- 7442 22