This is an Overly Complex Random Number Generator, created to demystify how containers work.
Easy peasy lemon squeezy. 🍋💦
-
docker-compose up --build
-
Visit
localhost
Below is an excerpt from my Blog Post about this.
- User sets a Random Seed
- Clicks Generate a Random Number
- Random Number is generated
- You have an understanding of Docker and Docker Compose
- You have heard about Python, React and Redis
- To illustrate how containerization actually looks in the wild
- We will be skipping how the actual Python, JavaScript Apps work, as we want to focus on containerization here, you can find all of the code on Github - CT83/The-Complicated-Simple-Container-App
- Nginx Proxy - Exposed on port 80, Manages networking
- React Dev Server - Accepts Input, Supports Live Reloading, Replaced with Nginx in Production
- Flask Server - Serves the API
- Redis Cache - To maintain the Task Queue
- Python Worker - Uses specified Seed to Generate Random Number, stores it in DB
- Database - PostGreSQL DB to store generated random numbers
- React App is served, user inputs the random seed.
- Seed is sent to the Flask API through a POST
- Task is added to Queue
- Worker picks up the task, generates a random number and store result in the database
- Result is returned to the user.
Here, is the minified docker-compose-prod.yml
version: "3.3"
services:
proxy:
container_name: proxy
build:
...
ports:
- 80:80
database:
container_name: database
build: database/.
volumes:
- ./database/db_data:/var/lib/postgresql
...
client:
container_name: client
build:
...
environment:
...
api:
container_name: api
build:
...
volumes:
- ./api:/app
worker:
container_name: worker
build:
...
redis:
container_name: redis
build:
...
You can find the development docker-compose.yml here. It even supports Live Reloading for both, the Flask and React Container!
You could now move on to trying to push the built images to DockerHub, or add TravisCI integration!
Stephen Grider in his Udemy Course Docker and Kubernetes: The Complete Guide built an overly complex simple app, that greatly inspired me.