Run Your Dockerized Microservices Voting App

Hritik RajHritik Raj
3 min read

Imagine your application isn't just one piece of software, but a team of services – like a web frontend, a database, and a backend API. Each of these might need its own Docker container.

This is where Docker Compose comes in. It's a tool for defining and running multi-container Docker applications. Instead of manually starting each container with complex docker run commands and linking them, you describe your entire application stack in a single docker-compose.yml file.

Think of Docker Compose as the conductor of your container orchestra. You define your services (like the web app, database, and message queue), their configurations, how they connect, and their dependencies in this YAML file. Then, with a single command (docker compose up), Docker Compose reads this file and spins up, connects, and manages all your services together.

It vastly simplifies the development, testing, and deployment of complex applications by automating the orchestration of multiple containers.

Image description

Got a multi-service application sitting in a GitHub repository, ready to be deployed with Docker Compose? Excellent! This quick guide is for you. We'll get your entire voting application stack up and running with just a few terminal commands.

This project features:

  • A Python/Flask Vote App

  • Redis for messaging

  • A .NET Worker

  • A PostgreSQL Database

  • A Node.js/React Result App

Image description

Let's dive straight into the commands!


Prerequisites

Make sure you have these installed on your system:


Step 1: Get Your Project Ready

First, clone your repository and navigate into the project directory.

# Clone your repository
git clone https://github.com/dockersamples/example-voting-app.git

# Navigate into your project directory
cd example-voting-app

Make sure you are in the root directory where your docker-compose.yml file and service subdirectories (vote/, worker/, result/) are located.

Step 2: Build and Run the Entire Application Stack

This single command will build all necessary Docker images, pull official ones, create networks, set up volumes, and start all services in the correct order.

docker compose up --build

This command will stream the build and runtime logs directly to your terminal. Wait until you see messages indicating services are started.

Step 3: Access Your Applications

Once the services are running, open your web browser to these URLs:

  • Voting App:

      http://localhost:8080
    
  • Result App:

      http://localhost:8081
    

Image description

Image description

Cast vote and check the result:

Image description

Image description

Step 4: Verify Running Containers (Optional)

To see all the containers currently running for your project:

docker ps

Step 5: Clean Up Your Environment

When you're finished experimenting, you can stop all containers, remove them, and clean up the network and any associated data volumes.

docker compose down -v

The -v flag is important here; it ensures your PostgreSQL database volume (db-data) is also removed, clearing any saved data.

0
Subscribe to my newsletter

Read articles from Hritik Raj directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Hritik Raj
Hritik Raj