Intro to Docker

A presentation at NewHavenIO - Containers/Kubernetes Talks in March 2019 in New Haven, CT, USA by Henry Quinn

Slide 1

Slide 1

HENRY QUINN INTRO TO DOCKER

Slide 2

Slide 2

ABOUT ME ▸ NewHaven.IO ▸ Member Board of Directors ▸ U.S. District Court, District of Connecticut ▸ Programmer, Analyst, Database Administrator ▸ Administrative Office of the US Courts ▸ Software Developer - Temporary Duty Assignment

Slide 3

Slide 3

AGENDA PLAN FOR TODAY ▸ What I Was Tasked With ▸ What Was Expected Of Me ▸ VPS Overview (Virtual Private Server) ▸ What I Did Instead ▸ Docker Overview

Slide 4

Slide 4

WHAT I WAS TASKED WITH GET A COLDFUSION APP IN 16 COURTS IN UNDER A YEAR ▸ CONSTRAINTS ▸ Finish The Application ▸ Get It Cleared As Secure By IT Security Office ▸ Requisition Servers ▸ Install, Configure, And Test Applications

Slide 5

Slide 5

WHAT WAS EXPECTED OF ME AO CONTROLLED VIRTUAL PRIVATE SERVERS

Slide 6

Slide 6

WHAT WAS EXPECTED OF ME FROM NOTHING ▸ Contact AO To Allocate Space And Install CentOS ▸ Log In With SSH ▸ Change Root Password ▸ Set Up Fail2Ban ▸ Configure Firewall ▸ Install And Configure Java, Apache Tomcat, ColdFusion, MySQL ▸ Take Periodic Snapshots ▸ Git Clone My Repo ▸ Configure Separate Directories For Each Specific Judge ▸ Set Up A Custom Domain ▸ Fly To District To Spot Check Data And Train Administrators ▸ Final Hand Off

Slide 7

Slide 7

WHAT WAS EXPECTED OF ME PROBLEMS WITH THAT ▸ It takes a week. ▸ We don’t control other districts’ hardware. ▸ It takes even more work to set up failover solutions. ▸ Setting up directories of static code per judge doesn’t make sense. ▸ This all doesn’t leave very much time for future development efforts.

Slide 8

Slide 8

WHAT I DID INSTEAD INFRASTRUCTURE AS CODE

Slide 9

Slide 9

WHAT I DID INSTEAD INFRASTRUCTURE AS CODE

Slide 10

Slide 10

WHAT I DID INSTEAD INFRASTRUCTURE AS CODE

Slide 11

Slide 11

WHAT I DID INSTEAD INFRASTRUCTURE AS CODE

Slide 12

Slide 12

WHAT I DID INSTEAD INFRASTRUCTURE AS CODE

Slide 13

Slide 13

WHAT I DID INSTEAD INFRASTRUCTURE AS CODE

Slide 14

Slide 14

WHAT I DID INSTEAD INFRASTRUCTURE AS CODE

Slide 15

Slide 15

WHAT I DID INSTEAD INFRASTRUCTURE AS CODE

Slide 16

Slide 16

WHAT I DID INSTEAD INFRASTRUCTURE AS CODE

Slide 17

Slide 17

WHAT I DID INSTEAD INFRASTRUCTURE AS CODE

Slide 18

Slide 18

WHAT I DID INSTEAD INFRASTRUCTURE AS CODE

Slide 19

Slide 19

WHAT I DID INSTEAD INFRASTRUCTURE AS CODE

Slide 20

Slide 20

WHAT I DID INSTEAD INFRASTRUCTURE AS CODE

Slide 21

Slide 21

WHAT I DID INSTEAD INFRASTRUCTURE AS CODE

Slide 22

Slide 22

WHAT I DID INSTEAD INFRASTRUCTURE AS CODE

Slide 23

Slide 23

WHAT I DID INSTEAD BROAD OVERVIEW ▸ Docker is a container management engine. ▸ Containers are builds that run the same on every platform. ▸ Containers are built from images, kind of like an .ISO file. ▸ Images are built using Dockerfiles. ▸ Dockerfiles are just text files with lists of instructions on how to build, configure, and run your environments.

Slide 24

Slide 24

WHAT I DID INSTEAD DOCKERFILES (PSEUDOCODE) FROM lucee/lucee5:5.0.1.85 COPY config/lucee/setenv.sh /usr/local/tomcat/bin/ COPY config/lucee/lucee-web.xml.cfm /opt/lucee/web/ COPY config/lucee/lucee-server.xml /opt/lucee/server/ lucee-server/context/ ENV ELI_DSN_DRIVER=MySQL \ ELI_DSN_CLASS=org.gjt.mm.mysql.Driver \ … COPY code/ /var/www/

Slide 25

Slide 25

WHAT I DID INSTEAD IMAGES ▸ An image is an inert, immutable file that’s essentially a snapshot of a container. ▸ Images are created from Dockerfiles, which are made of instructions that build layers on top of a metaphorical system. ▸ Running “build” on a Dockerfile creates an image, while running “run” on an image spawns an instance of that image. ▸ A running instance of an image is called a container, of which you can have multiple based on the same image.

Slide 26

Slide 26

WHAT I DID INSTEAD CONTAINERS

Slide 27

Slide 27

WHAT I DID INSTEAD BUILDING AN IMAGE ▸ $ docker build —rm -t quinncuatro/eli-lucee . ▸ Boring Nerd Stuff ————>

Slide 28

Slide 28

WHAT I DID INSTEAD USING AN IMAGE TO MAKE A CONTAINER ▸ $ docker images | grep eli-lucee ▸ $ docker run -d -p 127.0.0.1:8888:8888 —restart always -name eli-lucee —mount type=bind,source=$(pwd)/ code,target=/var/www quinncuatro/eli-lucee:latest ▸

Slide 29

Slide 29

WHAT I DID INSTEAD VERIFYING THAT THE CONTAINER IS RUNNING ▸ $ docker ps -a | grep eli-lucee

Slide 30

Slide 30

WHAT I DID INSTEAD PROBLEMS WITH THAT ▸ It’s only one container. ▸ It’s not connected to a database. ▸ How would we even persist the database container’s data? ▸ If we set a database container up, how do we make the containers talk?

Slide 31

Slide 31

WHAT I DID INSTEAD DOCKER COMPOSE YAML version: “3.5” services: lucee-eli: build: context: ./lucee dockerfile: Dockerfile container_name: eli-lucee ports: - “8888:8888” networks: - eli-net db-eli: build: context: ./mysql dockerfile: Dockerfile container_name: eli-db volumes: - eli_dbdata:/var/lib/mysql networks: - eli-net volumes: eli_dbdata: networks: eli-net: driver: bridge

Slide 32

Slide 32

WHAT I DID INSTEAD CREATING MULTIPLE CONTAINERS WITH DOCKER-COMPOSE ▸ $ docker-compose up -d ▸ $ docker ps -a

Slide 33

Slide 33

WHAT I DID INSTEAD VERIFYING THAT THE CONTAINERS ARE RUNNING

Slide 34

Slide 34

WHAT I DID INSTEAD NOW LETS ITERATE EVEN FASTER ▸ In spinup.sh (a bash script that executes different sets of Docker commands for me) there’s a line: ▸ $ docker run -d -p 127.0.0.1:8888:8888 —restart always — name eli-lucee —mount type=bind,source=$(pwd)/lucee/ code,target=/var/www —network eli-net devc_luceeeli:latest ▸ —mount type=bind,source=$(pwd)/lucee/code,target=/ var/www

Slide 35

Slide 35

WHAT I DID INSTEAD PLATFORM AGNOSTIC ▸ Docker can generate containers that run the same no matter where they are, whether it be: ▸ Windows 10/Server ▸ OS X >= 10.11 (El Cap) ▸ CentOS, Debian, Fedora, RHEL, SUSE, Ubuntu ▸ AWS ▸ Azure ▸ GCE

Slide 36

Slide 36

WHAT I DID INSTEAD PLATFORM AGNOSTIC ▸ Now, why is that a benefit? ▸ You can spin your apps and data layers up REALLY fast. ▸ No hand configs when trying out new tools, just “$ docker run ${whatever}” and go. ▸ Develop and deploy with the exact same point releases of operating systems and dependencies. ▸ Ensures that your applications are isolated and segregated. ▸ Use the same image through the entire CI process.

Slide 37

Slide 37

WIND DOWN PLAN FOR TODAY ▸ What I Was Tasked With ▸ What Was Expected Of Me ▸ VPS Overview (Virtual Private Server) ▸ What I Did Instead ▸ Docker Overview

Slide 38

Slide 38

RESOURCES HELPFUL LINKS (DIGITAL OCEAN) ▸ Digital Ocean Referral Code (Free $10 Credit) ▸ https://m.do.co/c/c4539d6703fe ▸ Digital Ocean CentOS Guides ▸ https://www.digitalocean.com/community/tutorials/ initial-server-setup-with-centos-7 ▸ https://www.digitalocean.com/community/tutorials/howto-install-linux-apache-mysql-php-lamp-stack-on-centos-7

Slide 39

Slide 39

RESOURCES HELPFUL LINKS (DOCKER) ▸ Install Docker CE (Community Edition) ▸ https://docs.docker.com/engine/installation/ ▸ Getting Started ▸ Mac - https://docs.docker.com/docker-for-mac/ ▸ PC - https://docs.docker.com/docker-for-windows/ ▸ Docker Labs - https://github.com/docker/labs