Saturday, July 16, 2016

Docker DevOps Around the Globe

When I completed the Docker Birthday #3 App Challenge I was presented with the following telling globe image that shows where other lab completions were occurring around the Globe:

Successful Lab Completions Per Country

Analysis

The biggest surprise, for me, were the number of successful lab completions from the Nordic countries (Norway, Sweden, Finland).

Way to go up (and over) there!

Also of note:
  • More Mid East completions than India
  • Spain includes North Africa and that count was higher that I expected
  • The Kazakhstan count also includes Turkey
  • Participation from Africa
  • No participation from Australia or Far East


Please let me know if I interpreted these numbers properly. Perhaps, part of the map was missing from my view.

My Completion Certificate

That bumped the total count for the US East up to 214.

The Voting App

This is what the running app looked like:

Components

We developed an app using Docker Toolbox that included:

Front End

  • Python webapp which lets you vote between several options
  • Node.js webapp showing the results of the voting in real time

Back End

  • Redis Queue to collect new votes
  • Java Worker which consumes votes and stores them in the database
  • Postgres database backed by a Docker Volume

Architecture Diagram

Project Details

Docker-Compose YAML File


version: "2"

services:
  voting-app:
    build: ./voting-app/.
    volumes:
     - ./voting-app:/app
    ports:
      - "5000:80"
    networks:
      - front-tier
      - back-tier

  result-app:
    build: ./result-app/.
    volumes:
      - ./result-app:/app
    ports:
      - "5001:80"
    networks:
      - front-tier
      - back-tier

  worker:
    image: manomarks/worker
    networks:
      - back-tier

  redis:
    image: redis:alpine
    container_name: redis
    ports: ["6379"]
    networks:
      - back-tier

  db:
    image: postgres:9.4
    container_name: db
    volumes:
      - "db-data:/var/lib/postgresql/data"
    networks:
      - back-tier

volumes:
  db-data:

networks:
  front-tier:
  back-tier:


This Compose file defines

  • A voting-app container based on a Python image
  • A reslit-app container based on a Node.js image
  • A redis container based on a redis image, to temporarily store the data.
  • A Java based worker app based on a Java image
  • A Postgres container based on a postgres image
Note that three of the containers are built from Dockerfiles, while the other two are images on Docker Hub. To learn more about how they're built, you can examine each of the Dockerfiles in the two directories: voting-app, result-app. We included the code for the Java worker in worker but pre-built the image to save on downloads.

The Compose file also defines two networks, front-tier and back-tier. Each container is placed on one or two networks. Once on those networks, they can access other services on that network in code just by using the name of the service. To learn more about networking check out the Networking with Compose documentation.

To launch your app navigate to the example-voting-app directory and run the following command:


$ docker-compose up -d


This tells Compose to start all the containers specified in the docker-compose.yml file. The -d tells it to run them in daemon mode, in the background.

Last you'll need to figure out the ip address of your Docker host. If you're running Linux, it's just localhost, or 127.0.0.1. If you're using Docker Machine on Mac or Windows, you'll need to run:

$ docker-machine ip default It'll return an IP address. If you only have one Docker Machine running, most likely, that's 192.168.99.100. We'll call that . Navigate to http://:5000 in your browser, and you'll see the voting app, something like this:

References



This work is licensed under the Creative Commons Attribution 3.0 Unported License.