Introduction to Docker
Containerization is the new virtualization
What's this going to be all about?
So what is Docker?
- Container virtualization
- Build, pack, ship and run applications as containers
- Build once, run in many places
- Isolated and content agnostic
So why should I care?
- Easy (and lightweight!) way to model reality
- Devs care about their app, Ops cares about the containers
- Golden images without the overhead
Why developers care...
- A clean, safe, hygienic and portable runtime environment
- No worries about missing dependencies, packages and other pain points
- Run each app in its own isolated container, so you can run various versions of libraries and other dependencies
- Automate testing, integration, packaging
- Reduce/eliminate concerns about compatibility on different platforms
Why operations care...
- Make the entire lifecycle more efficient, consistent, and repeatable
- Increase the quality of code produced by developers
- Eliminate inconsistencies between development, test, and production environments
- Support segregation of duties
- Significantly improves the speed and reliability of continuous deployment and integration
So why not VMs or Cloud?
- Speed of deployment
- Portability
- Size aka cached layering FTW
- Density & Performance
- Cost
Technology Stack
- Runs (for now) on most Linux distros
- cgroups and namespacing
- Device Mapper or AUFS or vfs or <pluggable in future>
- lxc or <pluggable in future>
Building Docker images with a Dockerfile
FROM ubuntu
MAINTAINER James Turnbull "james@example.com"
RUN apt-get install -y apache2
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
EXPOSE 80
ENTRYPOINT ["/usr/sbin/apache2"]
CMD ["-D", "FOREGROUND"]
Building the image
$ sudo docker build -t="jamtur01/apache2" .
Pushing the image
$ sudo docker push jamtur01/apache2
Running the container
$ sudo docker run -d -p 80 -v /var/www/myapp jamtur01/apache2