Docker Compose Demo

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

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. 
    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 (not used for this demo but it is my next venture!)
    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/charleyza/DockerCompose
  5. Create a directory compose-demo
mkdir compose-demo
cd compose-demo

  1. With nano create the compose.sh shell script and paste in the values from github and mark the script as executable
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
sudo nano docker-compose.yml
right click to paste from your clip board 
crtl x 
y
[ENTER]
  1. Create the angular-web directory
mkdir angular-web
cd angular-web
  1. Copy or create these files into the directory ‘angular-web’
    1. Dockerfile
    2. index.html
    3. nginx.conf

  1. Edit the index.html file to use the IP of the VM and target the API port

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

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

  1. Run compose.sh

NOTE WHAT THE SCRIPT WILL DO:

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

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.

  1. Exit compose

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

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

Testing API

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.

Testing Angular

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

References

Leave a Reply