Docker & Local Dev

A crash course

Objectives

  • Learn about Docker
  • Learn about Compose
  • How these things come together in LDP

What is Docker?

A platform for running applications

What exactly is a container?

class NodeApp < DockerImage

    def initialize(node_version, env, port, command)
        @node_version = node_version
        @node_env =  env
        @port = port
        @command = command
    end

    def run
        @command
    end
    
end
dating_game = NodeApp.new(
    "0.10.32", 
    "dev", 
    8888, 
    "node app.js"
)

api_go_tinder = NodeApp.new(
    "0.10.32", 
    "dev", 
    8088, 
    "node server.js"
)

tinder_auth = NodeApp.new(
    "0.10.32", 
    "dev", 
    8086, 
    "node app.js"
)

Docker Images

Docker Containers

OOP Analogy

Image Inheritence

  • Images based on other images.
  • Can be made, from scratch, but not typically needed.
  • Includes caching.

 

Understanding Dockerfiles

FROM elasticsearch

VOLUME /tmp/setup
ADD setup-elasticsearch.sh /tmp/setup/
ADD elasticsearch.yml /usr/share/elasticsearch/config/elasticsearch.yml

RUN "/tmp/setup/setup-elasticsearch.sh"

CMD ["elasticsearch"]

Docker Hub

Life Inside a container is lonely

$ ps aux
root node 1 11:04AM  node app.js

Docker Compose

Dealing with file systems and container linking on multiple containers can be a little complex. Docker compose makes this easy. 

docker-compose.yml

nodeapp:
  build: datinggame
  command: node app.js
  links:
   - db
  ports:
   - "8000:8000"
db:
  image: mongo

Local Dev Plus

./setup.sh

  • Makes your Docker Compose use local source code
  • Sets up environment to use Docker + Compose
  • Does some validation.
  • Set up debug mode by default.

Commands

 

  • dc up -d # Start all containers
  • dc stop # Stop all containers
  • dc build # Build all containers
  • dc ps # Check status of all containers
  • dtop # Check utilization of all containers

Dev Environments Before Docker

  • Run all services locally on OS X.
  • Run all services in a Linux VM using a snapshot base image.
  • Run all services in a Linux VM using Puppet/Chef for provisioning.
  • Run each service on it's own linux VM.
  • Maintain a special snowflake remote dev environment 

Docker & Local Dev

By Michael Martinez

Docker & Local Dev

  • 298