• Stars
    star
    179
  • Rank 206,793 (Top 5 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created about 9 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A short demo on how to use Docker Compose to create a Web Service connected to a load balancer and a Redis Database.

docker-compose scaling web service demo

A short demo on how to use docker-compose to create a Web Service connected to a load balancer and a Redis Database. Be sure to check out my blog post on the full overview - brianchristner.io

Install

The instructions assume that you have already installed Docker and Docker Compose.

In order to get started be sure to clone this project onto your Docker Host. Create a directory on your host. Please note that the demo webservices will inherit the name from the directory you create. If you create a folder named test. Then the services will all be named test-web, test-redis, test-lb. Also, when you scale your services it will then tack on a number to the end of the service you scale.

git clone https://github.com/vegasbrianc/docker-compose-demo.git .

How to get up and running

Once you've cloned the project to your host we can now start our demo project. Easy! Navigate to the directory in which you cloned the project. Run the following commands from this directory

docker-compose up -d

The docker-compose command will pull the images from Docker Hub and then link them together based on the information inside the docker-compose.yml file. This will create ports, links between containers, and configure applications as requrired. After the command completes we can now view the status of our stack

docker-compose ps

Verify our service is running by either curlng the IP from the command line or view the IP from a web browser. You will notice that the each time you run the command the number of times seen is stored in the Redis Database which increments. The hostname is also reported.

###Curling from the command line

```
curl -H Host:whoami.docker.localhost http://127.0.0.1

Hostname: 2e28ecacc04b
IP: 127.0.0.1
IP: 172.26.0.2
GET / HTTP/1.1
Host: whoami.docker.localhost
User-Agent: curl/7.54.0
Accept: */*
Accept-Encoding: gzip
X-Forwarded-For: 172.26.0.1
X-Forwarded-Host: whoami.docker.localhost
X-Forwarded-Port: 80
X-Forwarded-Proto: http
X-Forwarded-Server: a00d29b3a536
X-Real-Ip: 172.26.0.1
``` 

It is also possible to open a browser tab with the URL http://whoami.docker.localhost/

Scaling

Now comes the fun part of compose which is scaling. Let's scale our web service from 1 instance to 5 instances. This will now scale our web service container. We now should run an update on our stack so the Loadbalancer is informed about the new web service containers.

docker-compose scale whoami=5

Now run our curl command again on our web services and we will now see the hostname change. To get a deeper understanding tail the logs of the stack to watch what happens each time you access your web services.

```
docker-compose logs whoami
whoami_5         | Starting up on port 80
whoami_4         | Starting up on port 80
whoami_3         | Starting up on port 80
whoami_2         | Starting up on port 80
whoami_1         | Starting up on port 80
```

Here's the output from my docker-compose logs after I curled the whoami application so it is clear that the round-robin is sent to all 5 web service containers.

```
reverse-proxy_1  | 172.26.0.1 - - [01/May/2019:19:16:34 +0000] "GET /favicon.ico HTTP/1.1" 200 647 "http://whoami.docker.localhost/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36" 10 "Host-whoami-docker-localhost-1" "http://172.26.0.2:80" 1ms
```

More Repositories

1

prometheus

A docker-compose stack for Prometheus monitoring
4,208
star
2

docker-monitoring

Docker-Monitoring based on Cadvisor, InfluxDB, and Grafana
465
star
3

docker-traefik-prometheus

A Docker Swarm Stack for monitoring Traefik with Promethues and Grafana
309
star
4

github-monitoring

Monitor your GitHub Repos with Docker & Prometheus
261
star
5

grafana_dashboard

A Grafana Dashboard for monitoring Docker with Prometheus
58
star
6

crypto-currency-tracker

Track your Crypto Currencies with this Docker & Prometheus Stack
54
star
7

docker-pulls

A simple compose script to use in conjunction with the prometheus stack to monitor Docker pulls.
20
star
8

mac-background

A Python script which grabs random images from Unsplash and set it as your Mac OSX background image
Python
14
star
9

traefik-ghost

A Docker Stack using Traefik Proxy & Ghost 1.x
5
star
10

Ghost-Standalone

A Docker powered Ghost installation with volumes
CSS
4
star
11

webslides

A Dockerized version of http://www.Webslides.tv
4
star
12

vscode-docker-demo

Demo code for the DockerCon VS Code demo
Python
4
star
13

docker-ch-meetup10

10th Docker Switzerland User Group Meetup Docker Swarm Demo
4
star
14

docker-LAMP

A small Docker LAMP stack
3
star
15

docker-ecs-demo

This is a demo repo for deploying containers directly to AWS ECS
Python
3
star
16

linux_tweet_app

This a demo autobuild
HTML
2
star
17

traefik-migration

A Repo to help you migrate Traefik from 1.7 to 2.x
2
star
18

vegasbrianc

1
star
19

hugo

The really cool Hugo Static Website generator Dockerized
1
star
20

prom

Prometheus Docker Build
1
star
21

K8s-demo

Docker Kuberenetes Stack Demo
1
star