Skip to main content
Welcome to this hands-on demo of the Example Voting App. This sample application demonstrates how to build and deploy a simple microservices-based voting system using Docker. The complete source code is available in the Docker samples repository on GitHub under example-voting-app:
The image shows a GitHub repository page for an example Docker Compose app, listing files and directories along with commit details. The repository has 99 commits, 3 branches, and 13 contributors.
In this guide, we will:
  1. Review the overall architecture.
  2. Dive into each component’s source code and Dockerfile.
  3. Deploy all services step by step with docker run.

Architecture Overview

The voting system consists of five microservices:
The image is a diagram showing the architecture of a voting application. It includes components like a Python voting app, a Node.js result app, Redis, a PostgreSQL database, and a .NET worker, with arrows indicating data flow between them.

1. vote (Python Flask)

The vote service provides a simple web page to cast votes and pushes each vote into Redis. Navigate to the vote directory to explore its code and Dockerfile:
The image shows a GitHub repository page for "dockersamples/example-voting-app" with a list of files and directories, including "Dockerfile" and "app.py". The page is in the "vote" directory of the master branch.

app.py

The Redis host is referenced as redis. Ensure the Redis container is linked or networked under this name.

Dockerfile


2. worker (Java)

The worker service consumes vote messages from Redis and writes them into PostgreSQL.

Worker.java

Dockerfile


3. result (Node.js/Express)

The result service queries PostgreSQL for vote counts and renders a results page.

server.js

Dockerfile


4. Deploying with docker run

The --link flag is considered legacy. For production, prefer user-defined networks or Docker Compose.

4.1 Clone & Build the Voting UI

4.2 Start Redis & Voting UI

Open http://localhost:5000 to cast your vote.

4.3 Launch PostgreSQL Database

4.4 Build & Run the Worker

4.5 Build & Run the Result App

Visit http://localhost:5001 to see live voting results:
The image shows a voting result with "CATS" at 100.0% and "DOGS" at 0.0% on a blue background. There is one vote recorded.

Congratulations! You’ve manually deployed all services using docker run, linked them together, and completed a full voting workflow. Next, we’ll automate this setup with Docker Compose.

References

Watch Video