%title: Docker for Homo Troglodytes %author: Cody Hiar %date: 2019-01-15 -> Docker for Homo Troglodytes <- ================================= ------------------------------------------------- # About Me * Graduated Computer Engineering at U of A * Now working remotely @ Blendable * Vim/Tmux Diehard, also cli in general * Interests: Python, Automation, DevOps, Linux # Where I be * www.codyhiar.com * www.github.com/thornycrackers # Past Presentations (available on GitHub) * Scraping with scrapy (YEGSEC) * Python Daemons (Edmonton.py) * Setting Django up on a VPS (Edmonton.py) ------------------------------------------------- -> My Goals <- ============== * Help build a mental model of Docker * Introduce Docker basics * Give some working examples for possibilites -> My Assumptions <- ==================== * You know what the concept of a VM is * Little to no experience with Docker * You know _some_ linux * Take things with a grain of salt ------------------------------------------------- -> What is Docker? <- ==================== ``` Docker == VM // True Docker === VM // False ``` ^ For all intents and purposes, you can use your mental model of a VM for Docker. Some people will argue that there is a difference, usually their answers are ostentatious. ------------------------------------------------- Handy Chart of Advantages ========================= | Feature | VM | Docker | | ----------- | -- | ------ | | Size | ** | ** | | Startup | ** | ** | | Integration | ** | ** | Docker vs Vagrant MBs vs GBs Seconds vs Minutes ------------------------------------------------- -> Installation <- ================== - Mac/Windows https://www.docker.com/get-started - Linux: https://www.digitalocean.com/community/tutorials /how-to-install-and-use-docker-on-ubuntu-16-04 (Article includes CentOs 7, Debian 9, Ubuntu 18.04) ------------------------------------------------- -> Pfffft Let's see it <- ========================= example1.sh demo - Run script - Explain commands - Look at execution time - Look at image size ------------------------------------------------- -> What Happened? <- ==================== > "What goes up must come down" -Isaac Newton 1. Docker looked for image (Downloads if needed) 2. Docker spins up a container 3. Container runs `echo Hello World` 4. Docker spins down the container 4. Docker removed the container There will be no demo of a VM time equivalent ------------------------------------------------- Q: If the time difference between running a command on the machine and running a command in a container is negligible, then why don't we start running all commands inside of containers? ------------------------------------------------- A: We don't understand Docker yet. But after this we will! ------------------------------------------------- -> Let's dockerize the 'date' command <- ======================================== example2.sh demo - show `date` command - show script with docker command explain '$@' args - run `date -d yesterday` locally and with script - move script to somewhere on $PATH to execute ------------------------------------------------- As you can see the run time of the command inside the container is blazingly fast. `date` was already built into the container so look at how to install a package. ------------------------------------------------- -> Introducting Docker Files <- =============================== Docker images are synonymous with VM snapshots. They take a 'picture' of the current container. While it is possible to start a container, install/set it up, and then export the container as an image, the best way to create images is by using a Dockerfile. Dockerfiles are step by step set of instructions on how to create an image that will be able to run an application. ------------------------------------------------- -> Let's dockerize Vim <- ========================= example3.sh demo - Show Dockerfile - Show script, explain docker build - Explain layers for caching and build context - Explain the volumes for mounting files ------------------------------------------------- -> A Quick Intermission: <- =========================== -> Compiled vs Intepreted Programming Languages <- ================================================== Once upon a time, programming langauges were compiled to binaries and everyone was happy. Then the evil Alan Kay led the creation of Smalltalk at Xerox PARC which influenced future programming languages with evil concepts like object oriented programming and compiling at run time. Now we have to live with the evil Alan Kay's cruel intentions and will never know true happiness again. The End ------------------------------------------------- -> Using language specific images <- ==================================== Some langauges, such as python, ruby, and javascript, are compiled at run time when they are run. This means that you need to have that language's ecosystem installed on your machine to run a tool programmed in that language. Docker provides official images for many languages which provide required low level libraries and usually the languages package manager so that you can quickly get up and running. Now we don't have to pick tools based on their languages. ------------------------------------------------- -> Let's dockerize Babysploit <- ================================ example4.sh demo - Babysploit provides own container, we'll try our own - Show Dockerfile and script ------------------------------------------------- -> A Beginner's Summary <- ========================== - We have a loose general idea of what Docker is - We've seen how fast/small docker images are - We have a framework for running images similar to binaries - Dockerfiles provide us with step by step instructions on how to build the environment for an application as well as define the boundaries of an application - We can use tools written in languages we don't know without having to research how to set the the languages environment, and even do development on the tool ------------------------------------------------- -> What about GUI Apps? <- ========================== Ok let's kick it up. So far we've only been working with simple binaries on the command line but docker is capable of much, much more. How about GUI aplications? * Note: This is for linux only, sorry mac/windows * ref: https://blog.jessfraz.com/post/ * docker-containers-on-the-desktop/ ------------------------------------------------- -> Let's dockerize Spotify <- ============================= example5.sh demo - Explain how display can be shared with volumes - Run spotify ------------------------------------------------- -> Managing Multiple Containers? <- =================================== Docker compose is a tool for defining multi container environments that allow us to create a repeatable infrastructure setup so that we can build complex environments that have complex requirements.