docker
TRANSCRIPT
DockerNarato DevOps Series
Agenda
What is docker and why use it The basic docker tools Docker during development Docker during CI and testing Docker in production Q & A
Not on the agenda
How do docker or linux containers actually work
What is Docker?
“Docker allows you to package an application with all of its dependencies into a standardized unit for software development.”
What is Docker?
Docker is an opinioned implementation for building, shipping and deploying applications as standalone containers.
What are docker containers?
Docker containers are a Linux technology!
What are docker containers?
Why?Why would we want to use them?
Why?Languages .NET, NodeJS, Java,
Python. Go, …
ApplicationsWeb Services,
Background Workers, Databases, …
Libraries.NET Framework, ExpressJS, Django, Ruby On Rails, …
Modern architectures have a diverse ecosystem.
More sources to handle.
Why?
Development Environment
Production Environment
Test Environment
IoT Devices Cloud Providers
Virtual Machines
Shared Hosting
CI Environment Linux
Windows OS X QA Environment
Bare Metal
More targets to handle.
Why?
Networking, security, orchestration, oh my …
Virtual Machines vs Docker
The container perspective
Containers
Many products
Containers
Many transports
Linux Containers
Distro and vendor neutral environment for the development of Linux container technologies.LXC, LXD, …
https://linuxcontainers.org/
Alternatives to Docker
Linux Containershttps://linuxcontainers.org/
Flockporthttps://www.flockport.com/
Rocket (CoreOS)https://github.com/coreos/rkt
Drawbridge (Microsoft)http://research.microsoft.com/en-us/projects/drawbridge/
LXD (Ubuntu/OpenStack)http://www.ubuntu.com/cloud/lxd
Windows Containershttps://msdn.microsoft.com/en-us/virtualization/windowscontainers/quick_start/manage_docker?f=255&MSPPError=-2147217396
Even Microsoft joins in
https://azure.microsoft.com/en-us/blog/new-windows-server-containers-and-azure-support-for-docker/
https://azure.microsoft.com/en-us/blog/containers-docker-windows-and-trends/ https://msdn.microsoft.com/en-us/virtualization/windowscontainers/quick_start/manag
e_docker?f=255&MSPPError=-2147217396
Docker Tools
Docker Products
docker-machine
Automate Docker provisioning.
docker-machine
docker-machine [command] [machine-name]
docker-machine start default
docker-machine status default
docker-machine env default
docker engine
Docker Engine runs on Linux to create the operating environment for your distributed applications.
docker engine
docker [options] command [arg...]
docker imagesdocker psdocker build .docker run –p “8888:8888” image_name
docker-compose
Docker Compose allows you to define your multi-container application with all of its dependencies in a single file, then spin your application up in a single command.
docker-compose
docker-compose [options] [command] [args]
docker-compose updocker-compose startdocker-compose stopdocker-compose builddocker-compose psdocker-compose scale service=2
swarm
Docker Swarm provides native clustering capabilities to turn a group of Docker engines into a single, virtual Docker Engine.
swarm
Can run as a container on a docker engine instance.
docker run swarm
Using Docker in development
Docker in the development part of Application Lifecycle Management
Development
FROM nodeMAINTAINER Stefan Alaerts <[email protected]>
RUN apt-get update -qq && apt-get install -y build-essential
RUN mkdir /eventhandler-api-serviceCOPY . /eventhandler-api-service/WORKDIR /eventhandler-api-service
ENV NODE_ENV production
RUN npm install
EXPOSE 8888
CMD node lib/index.js
Use a Dockerfile to describe how docker should build an image for your application.
The resulting image should preferably be self-contained.
Development
https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/
Use the best practices when authoring Dockerfiles.
Development
docker build –t {tag} .
Build images using docker engine.
Development
version: '2'
services:bus: image: rabbitmq:3-management ports: - "15672:15672" - "5672:5672" hostname: eventhandler-bus
api: build: ./src/api ports: - "8888:8888" hostname: eventhandler-api environment: - CONFIGURATION_URL=eventhandler-configuration - CONFIGURATION_PORT=4050 - BUS_URL=eventhandler-bus command: nodemon -L lib/index.js
Use a docker-compose.yml file to describe configuration for multiple containers.
Development
docker-compose up
Use docker-compose to run all of your containers as a single unit.
Tips for Windows usersDon’t suspend your computer while docker-machine is running a machine in VirtualBox.Doing so often breaks networking.
Tips for Windows usersWhen using volumes, make sure your project folder is inside your user home directory. (VirtualBox shared folders limitation.)
Tips for Linux usersUse the power of the command line to remove all images with one command:docker rm `docker ps -aq`
Tips for all usersUse the docker-compose extends functionality.You can auto-reload your application in development by sharing your code using volumes while embedding the code in production.
Most production tools (Docker Cloud, Rancher, …) also support extending compose configurations.
Tips for all usersYou can access the shell of a running container if you need it.
docker exec –i –t [container_id|container_name] bash
Using Docker after development
Docker in the CI and testing part of Application Lifecycle Management
Extending development flow
Docker Machine (Windows, OSX)Docker EngineDocker Compose
Application Lifecycle Management
https://blog.docker.com/2015/09/docker-hub-2-0/
DevOps with Docker
http://thenewstack.io/how-docker-fits-into-the-devops-ecosystem/
DevOps with Docker
https://dzone.com/articles/docker-hub-20-integration-with-the-cloudbees-jenki
Tools for production
Docker Cloud (previously Tutum) Rancher Deis
http://deis.io/ Atomic
http://www.projectatomic.io/
Example: deploying a NodeJS blog
docker login --username=salaerts [email protected] docker build –t salaerts/blog . docker push salaerts/blog
Example: deploying a NodeJS blog
git push origin master Docker Hub kicks off an automated build on each push