Day 22: Scaling My Flask App Like a Pro with Docker Compose Orchestration


Refining Service Orchestration
I opened docker-compose.yml with nano docker-compose.yml and got to work. I tweaked the web service (my Flask app) to depend on redis with a service_healthy condition, ensuring Redis is ready before Flask starts. I also added a restart: unless-stopped policy for resilience and a deploy section for scaling:
web:
build: .
image: flask-app:1.0
depends_on:
redis:
condition: service_healthy
required: true
restart: unless-stopped
deploy:
replicas: 3
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
update_config:
parallelism: 1
delay: 10s
order: start-first
labels:
- "com.example.d: Blogging and Community Engagement (15 Minutes)
Finally, I wrapped up by updating my Week 4 blog notes and boosting my online presence. In week_4_blog_notes.txt, I added:
“Enhanced Flask + Redis app with Docker Compose orchestration and scaling.”
“Practiced docker compose scale, tested Nginx load balancing.”
“Explored 2025 orchestration trends via Grok DeepSearch on X.”
I asked Grok for a 50-word blog section: “Docker Compose orchestration streamlined my Flask app’s reliability. Dependencies, health checks, and restart policies ensured smooth startups. Scaling with docker compose scale and Nginx load balancing optimized performance. Grok’s DeepSearch revealed 2025 trends, making orchestration a game-changer for scalable apps!” I added this to my notes.
On Hashnode, I updated my bio: “Usman Jap, 22+ years in IT, mastering Grok and Docker on Linux. Day 22: Scaled Flask app with Compose orchestration!” I linked my Day 21 post for continuity. On X, I posted:


Day 22: Scaled Flask + Redis app with Docker Compose orchestration! Loving `scale` for load balancing. #Docker #Grok #Kubernetes
I also commented on a @docker post: “Orchestration in Compose—any 2025 tips?” For my blog prep, I noted three Week 4 takeaways:
Orchestration ensures service reliability.
Scaling optimizes load distribution.
X and Grok highlight 2025 trends.
Outcome: My Hashnode profile is popping, and I’m connecting with the Docker community on X!
Wrapping Up: Why Day 22 Rocked
Today was a blast—scaling my app felt like giving it superpowers! I learned how docker compose scale and Nginx create a load-balanced dream team, while orchestration keeps everything in harmony. Grok’s insights and X’s community vibe kept me inspired. My resume now boasts “Docker Compose Service Orchestration and Scaling” for Month 1.
Tips for Success:
Check Docker/Compose status: sudo systemctl status docker, docker compose version.
End with active recall: Explain docker compose scale in day_22_notes.txt.
Review Day 21 overlay networks for spaced repetition.
Engage on X: Reply to a #Docker post like “Scaling tips for Compose?”
What’s Next? Day 23 (June 20, 2025) dives into advanced logging strategies—log rotation, external services, and more Flask app tweaks. I’ll also keep my Hashnode and X game strong. Want to follow along? Check my GitHub (https://github.com/<your-username>/flask-redis-app) and join me on X (@UsmanJap) for more #Docker adventures!
Word Count: 1000
Resources: Docker Docs, FreeCodeCamp, TechWorld with Nana (YouTube), Grok (free tier), Hashnode, X (@docker, @xAI)
Let’s keep scaling the heights of DevOps together!escription=Flask app for development"
- "com.example.role=web"
networks:
- app-net
I also ensured my nginx-dev service depends on web with a health check, keeping everything in sync. To track scaling, I updated app/app.py to log instance IDs:
import os, logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
logger.info(f"Starting Flask app with instance ID: {os.getpid()}")
Scaling and Load Balancing
Now for the fun part—scaling! I updated nginx-dev.conf to balance traffic across web replicas:
events {}
http {
upstream flask_app {
server web:5000;
server web:5000;
server web:5000;
}
server {
listen 80;
location / {
proxy_pass http://flask_app;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
}
I fired up the app with docker compose --profile dev up -d --build, then scaled it: docker compose scale web=5. A quick docker compose ps confirmed five web containers running. To test load balancing, I ran:
for i in {1..10}; do curl http://localhost:8080; done
The responses showed different visit counts (thanks, Redis!), proving Nginx was distributing traffic. I checked logs with docker compose logs web | grep "Starting Flask app"—yep, unique PIDs for each replica!
Simulating Failure
To test resilience, I stopped Redis with docker compose stop redis and hit curl http://localhost:8080. As expected, I got a 500 error: “Error connecting to Redis.” I debugged with docker compose logs web, spotting the connection issue. Restarting Redis (docker compose start redis) and running docker compose --profile dev up -d --wait restored the app. I committed my changes to GitHub:
git add docker-compose.yml nginx-dev.conf app/app.py
git commit -m "Enhanced orchestration and scaling with load balancing"
git push origin main
Next, I got hands-on with orchestration commands and tapped Grok for deeper insights. Back in my terminal, I played with scaling and updates.
Orchestration Commands
I scaled down with docker compose scale web=2 and checked with docker compose ps—two containers, as expected. I simulated a rolling update with docker compose up -d --build web, watching Compose gracefully update my Flask service. I asked Grok: “Explain Docker Compose orchestration commands in 100 words.” Grok’s response was spot-on, detailing up, down, scale, ps, logs, and exec for managing service lifecycles.
Grok Queries
I crafted three prompts for Grok:
“Explain best practices for Docker Compose service orchestration in 150 words, with a 2025 example.” Grok suggested health checks, restart policies, and custom networks, using a Flask + Redis example like mine.
“How does docker compose scale enable load balancing in 100 words?” Grok explained how scaling creates replicas, paired with Nginx for traffic distribution.
I also used think mode on grok.com: “Step-by-step, how does Docker Compose orchestrate services?” Grok walked me through defining services, dependencies, networks, and scaling—super clear!
Testing Scaling Limits
I updated docker-compose.yml to limit replicas:
deploy:
replicas: 3
resources:
limits:
cpus: '0.5'
memory: 256M
mode: replicated
placement:
max_replicas_per_node: 2
I tried docker compose scale web=10, expecting an error due to the max_replicas_per_node limit. Sure enough, only two replicas started per node. I reverted the change, committed it, and pushed to GitHub.
Outcome: I’m now a Compose command ninja, with Grok as my sensei!
Subscribe to my newsletter
Read articles from Usman Jap directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
