CUNY Codes Fall 2017 Docker

Robby O'Connor

Created: 2017-09-25 Mon 19:39

Introduction

Hunter College CS Alum (Fall 2014)

CUNY Codes Alum (Spring 2016) and Peer Mentor

Infrastructure Engineer/Steering Committee Member for LibreHealth(http://librehealth.io)

I Really Love Docker – A LOT!

What is Docker

Docker is a way to run containerized applications.

What does this mean?

Isolated from all other processes, much like a virtual machine.

The isolation pertains to: process id, networking, interprocess communication (IPC), mounts, and unix timesharing system.

The isolation mechanism is called namespaces. Another feature which is used is called control groups, or cgroups.

cgroups allow you to limit resource usage.

A container is not real thing, it's what the namespaces and cgroups when pulled together form.

Overview of Docker

Fundamentally different from Virtual Machines

vm.png container.png

Images

Networks

Volumes

Getting Docker

Docker provides support for Windows/Mac/Linux. though relies heavily on features embedded in the Linux Kernel to work.

Windows

Download Docker For Windows: https://docs.docker.com/docker-for-windows/install/

Mac

Download Docker For Mac: https://docs.docker.com/docker-for-mac/install/

Linux

For linux, using Ubuntu is probably the best: https://docs.docker.com/engine/installation/linux/ubuntu/

Our first Dockerfile (building our first Image)

What is an Image

An image is a set of instructions, which form immutable layers.

FROM node:8-alpine
LABEL maintainer "Robby O'Connor <robby.oconnor@gmail.com>"
CMD ["yarn","start"]
WORKDIR /app
RUN apk add --no-cache bash curl openssl git build-base gosu yarn \
--repository http://dl-3.alpinelinux.org/alpine/edge/testing/ \
--repository http://dl-3.alpinelinux.org/alpine/edge/community/
COPY docker/build.sh /
RUN bash /build.sh
COPY . /app
~
~
~
~
~
~
~
~

Where's the database and why do I care about Docker at all?

Less bootstrap time

One environment for everything!

Overview on Docker Compose

A tool to orchastrate containers. You will have a container per process.

Example: Your app will run in one, MySQL in another, and whatever other service you need.

Docker Compose files are specified using a language called YAML.

version: "2.1"

services:
  web:
    user: "${UID-1000}:${GID-1000}"
    build:
      context: .
    ports:
      - 0.0.0.0:3000:3000
    depends_on:
      mongodb:
        condition: service_healthy
    volumes:
      - .:/app
    restart: unless-stopped
    container_name: "app"
  mongodb:
    image: mongo:3.4
    ports:
      - "0.0.0.0:27017:27017"
    container_name: "_mongo"
    volumes:
      - ./data/mongo/db:/data/db
    healthcheck:
      test: ["CMD", "mongo", "--quiet", "localhost/test",
             "--eval","'quit(db.runCommand({ ping: 1 }).ok ? 0 : 1)';"]
      interval: 1m30s
      timeout: 10s
      retries: 3
    restart: unless-stopped
    command: "mongod --nojournal --smallfiles"
~
~
~
~
~
~
~
~

More Info

Slides: https://github.com/robbyoconnor/cunycodes-fall17-dockertalk

Docker User Guide: https://docs.docker.com/engine, https://docs.docker.com/compose