Module 5 Lesson 5: Real-World Multi-Container Example
·DevOps

Module 5 Lesson 5: Real-World Multi-Container Example

The capstone of the basics. Build a complete Voting App architecture with a Python worker, a Redis queue, a Postgres DB, and a Node.js results page.

Module 5 Lesson 5: Real-World Multi-Container Example

To wrap up our basics, let’s look at a "Real World" architecture. This is a classic example used in the Docker community to show how different languages and databases interact.

1. The Architecture

We want to build a Voting App:

  1. Voting-UI (Python): A web page where users click "Dogs" or "Cats".
  2. Redis (Queue): The vote is sent to a fast in-memory queue.
  3. Worker (.NET or Java): Reads the vote from Redis and saves it to a database.
  4. DB (Postgres): Permanent storage for the votes.
  5. Result-UI (Node.js): A dashboard that shows the current tally.

2. The Final docker-compose.yml

version: "3"

services:
  vote:
    image: dockersamples/examplevotingapp_vote:before
    ports:
      - "5000:80"
    networks:
      - front-tier
      - back-tier

  redis:
    image: redis:alpine
    networks:
      - back-tier

  worker:
    image: dockersamples/examplevotingapp_worker
    networks:
      - back-tier

  db:
    image: postgres:9.4
    volumes:
      - "db-data:/var/lib/postgresql/data"
    networks:
      - back-tier

  result:
    image: dockersamples/examplevotingapp_result:before
    ports:
      - "5001:80"
    networks:
      - front-tier
      - back-tier

networks:
  front-tier:
  back-tier:

volumes:
  db-data:

3. Key Observations

  1. Multiple Networks: Notice how redis, worker, and db are only on the back-tier. They cannot be reached by a user on the internet.
  2. Public Ports: Only the vote (port 5000) and result (port 5001) are published to the host.
  3. Independence: You can swap the .NET worker for a Go worker, and as long as it talks to the same Redis/Postgres hostnames, the system doesn't care.

4. Troubleshooting the Stack

If the result page shows 0 votes even though you clicked:

  • Check docker-compose logs worker. Is it connecting to Redis?
  • Is the db service healthy?
  • Are all containers on the same back-tier network?

Exercise: The Architect's Challenge

  1. Design: If you wanted to add a "Load Balancer" (like Nginx) in front of the vote app to handle 10,000 users, where would it go in the YAML file?
  2. Persistence: If the result app needs to save CSV exports of the votes, where should it save them? (Hint: add a new volume).
  3. Security: Why is it a good thing that the vote service is NOT on the same network as the db service directly?

Conclusion of Module 5

You have mastered Docker Compose. You can now build, link, and manage complex systems that previously would have taken a whole team of SysAdmins to configure.

Next Module: We dive into the "Production Grade" topics: Module 6: Advanced Dockerfile Techniques (Multi-stage builds and more).

Subscribe to our newsletter

Get the latest posts delivered right to your inbox.

Subscribe on LinkedIn