Docker Compose Demo

Dock Compose

To demonstrate the power of docker compose and Infrastructure as code (IaC) I put together the following functional example. I must also give credit to Godfrey Sisimogang for his input into the initial process flow – thank you my mate.

All of the source code is open source MIT and I encourage fellow software craftsmen to fork the scripts and adapt for functional use.

Overview

The Eco-systems is made up of the following layers

  1. Database
    1. postgres:9.6-alpine
  2. Git clone
    1. SQL scripts used with flyway to provision/version the database
    2. Scripts on GitHub
  3. Flyway
    1. fusebox/flyway:5.1
      1. Baseline
      2. Migrate
  4. API to communicate with the database
    1. postgrest/postgrest:v0.5.0.0
  5. Fizz buzz generator
    1. carlpaton/fizzbuzz:v1.1.0
    2. Source code
    3. What is Fizz Buzz
    4. Steps on how I got this image onto the docker store (community)
  6. Angular Web Application to GET and display the data
    1. Source code for application and config

Overview

Functional Use

To spin up the entire echo-system run ./compose.sh

Once you have run ./compose.sh above and then stop the services for what ever reason you can start just the Database and API with ./start.sh

Great but how do I run the shell scripts?

In my case my local laptop runs Windows 10 and the docker magic runs in a virtual machine using Oracle VM VirtualBox. The virtual machine runs Ubuntu Server this I felt was as close to the bare metal servers most corporate companys will be running.

  1. Create a new virtual machine with Virtual Box

    1. Set the ‘Network’ to ‘Bridged Adapter‘, the VM will then get an IP from your local DHCP service and be in the same range as your laptop.
      Run Scripts
    2. I used ubuntu-17.10.1-server-amd64.iso
  2. Boot into the OS & Install Docker CE

    1. There are steps here where I installed on VMWare Workstation Player
      1. I’ve opted to move over to VirtualBox as it plays nicely with Hyper V which will be necessary for kubernetes & minikube
    2. Installing SSH will allow you to putty to the server, this helps with the copy and paste steps.
  3. Install docker compose

  4. Clone these scripts from github to the local windows host

    1. Its possible to clone directly to the Ubuntu VM but thats up to you
    2. https://github.com/carlpaton/DockerCompose
  5. Create a directory compose-demo

    1
    2
    mkdir compose-demo
    cd compose-demo

Run Scripts

  1. With nano create the compose.sh shell script and paste in the values from github and mark the script as executable
1
2
3
4
5
6
7
sudo nano compose.sh
right click to paste from your clip board
crtl x
y
[ENTER]

sudo chmod +x ./compose.sh
  1. Repeat the above for the start.sh shell script

  2. With nano create the docker-compose.yml file and paste in the values from github

    1
    2
    3
    4
    5
    sudo nano docker-compose.yml
    right click to paste from your clip board
    crtl x
    y
    [ENTER]
  3. Create the angular-web directory

    1
    2
    mkdir angular-web
    cd angular-web
  4. Copy or create

    these files

    into the directory ‘angular-web’

    1. Dockerfile
    2. index.html
    3. nginx.conf
      Run Scripts
  5. Edit the index.html file to use the IP of the VM and target the API port

    Run Scripts

  6. Create the flyway-git-clone directory

    1
    2
    3
    cd ..
    mkdir flyway-git-clone
    cd flyway-git-clone
  7. Copy or create the Dockerfile into this directory

    Run Scripts

  8. Change back up a directory to ‘compose-demo’, your folder should look like this now

1
2
cd ..
ll

Run Scripts

  1. Run compose.sh

NOTE WHAT THE SCRIPT WILL DO:

a. The removal of containers
b. The removal of volumes (if found)

1
sudo ./compose.sh

This will then run though the overview layers above, once complete you can browse the angular container which will call the API and display the fizz buzz data.

Exit code 0 means the container completed its life without any issues.

Run Scripts

  1. Exit compose

    Run Scripts

1
CTRL C
  1. Display all the containers, note that the compose containers take their names from the name in the YML file.
1
sudo docker ps --all

Run Scripts

  1. You can now startup just the required containers with start.sh
    1. This will only start the database, API and Angular Web containers
1
sudo ./start.sh

You can then call the API directly, example http://10.0.0.108:3000/fizzbuzz_data

The IP of your container will depend on your Host VM and DHCP server.

Run Scripts

Testing Angular

You can then also call the angular application, example http://10.0.0.108:8080/

Run Scripts

References