Skip to main content
In this step-by-step tutorial, you’ll learn how to orchestrate a multi-service voting application using Docker Compose. By the end, you’ll have a running stack that includes Redis, PostgreSQL, a voting frontend, a worker processor, and a results dashboard.

Prerequisites

  • Docker Engine installed (version ≥ 19.03)
  • Basic familiarity with docker CLI
  • A terminal/SSH session on Linux, macOS, or Windows WSL

Step 1: Install Docker Compose

Docker Compose isn’t bundled with Docker Engine by default. Install it on Linux with:
Expected output:
Replace 1.16.1 with the latest stable release. See the Compose releases on GitHub for details.

Step 2: Clean Up Existing Containers

Before deploying, stop any previous demo containers:
Stopping containers will terminate running services. Ensure you don’t have unsaved data in those containers.

Step 3: Define Services in docker-compose.yml

Create a file named docker-compose.yml with the following content. It leverages Compose file format version 3.

Service Overview

The depends_on key ensures containers start in the correct order, but it doesn’t wait for health checks. Consider adding healthchecks for production workloads.
See the Compose file reference for advanced options.

Step 4: Deploy the Stack

From the directory containing docker-compose.yml, run:
This command will pull images, create a default network, and start all five containers. Container names are prefixed by your folder name (e.g., root_redis_1). Verify everything is up:
You should see containers for Redis, PostgreSQL, vote, worker, and result.

Step 5: Access the Application

Cast a vote on the first page, then switch to the results page to see real-time counts.
The image shows a webpage titled "Cats vs Dogs!" with two buttons labeled "CATS" and "DOGS," where "DOGS" is selected. It also mentions that you can change your vote and displays a container ID at the bottom.

Clean Up

When you’re done testing, stop and remove all services with:
This command stops containers and removes the network. Volumes and images remain unless you add the --volumes or --rmi all flags.

References and Further Reading

Watch Video