Day 07:Docker Compose with Docker Voting Application

"Hello, I'm Kiran Pawar, a passionate Cloud and Devops Engineer with a strong background in cloud automation, configuration, and deployment. My journey in the world of technology has been a thrilling adventure, where I've had the privilege to work with cutting-edge tools and practices.
๐ As a DevOps Engineer:
I specialize in automating, configuring, and deploying instances in cloud environments and data centers. My expertise extends to DevOps, GitOps, CI/CD pipeline management, HashiCorp Terraform, and containerization. I'm proficient in AWS and Linux/Unix administration, ensuring robust infrastructure and application performance.
๐ง My Tech Stack:
Front-end skills: HTML, CSS, SCSS, Tailwind CSS, Bootstrap, React, Material-UI, JavaScript DevOps toolbox: GIT, OWASP,Nexus,Trivy, Github, Gitlab, Terraform, Ansible, Docker, Kubernetes, Helm, Jenkins, Prometheus, Grafana, Argo CD, AWS EKS.
๐ My Cloud Expertise:
I have hands-on experience managing AWS services, including EC2, S3, EBS, VPC, ELB, RDS, IAM, Route53, and more.
๐ Networking and Security:
My skills include managing networking concepts such as TCP/IP protocols, security policies, and subnet interfacing. I have a strong understanding of infrastructure and networking, covering topics like firewalls, IP addressing, DNS, and more.
๐ก What Sets Me Apart:
I bring a positive attitude, a strong work ethic, and a collaborative spirit to every project. I'm a self-starter, a fast learner, and an effective team player with strong interpersonal skills. In addition to my DevOps skills, I've developed shell scripts (Bash) for automating tasks and have proficiency in Python scripting. My ability to communicate and manage projects, along with a track record of resolving client issues, adds value to every team I work with. If you're looking for a DevOps engineer who is also well-versed in front-end technologies, feel free to connect with me. Let's explore new possibilities and create exceptional technical solutions together!"
Introduction
Docker Compose is a powerful tool that simplifies the deployment of multi-container applications. It allows developers to define application services, networks, and volumes using a YAML file, enabling seamless orchestration and scaling of containerized applications.
In this blog, we will explore Docker Compose by deploying a sample voting application. This guide is complemented by a video tutorial available on the Mastering Cloud YouTube channel.
What is Docker Compose?
Docker Compose is a command-line tool that enables you to define and manage multi-container Docker applications. It uses a YAML configuration file (docker-compose.yml) to describe the services required to run an application, making it easy to:
Define multi-container applications
Manage service dependencies
Scale services efficiently
Handle networking and persistent storage
Prerequisites
Before getting started, ensure you have the following:
Docker installed on your machine
Basic understanding of Docker and containerized applications
Docker Compose installed (included with Docker Desktop)
Installing Docker Compose
The following command will download the 1.29.2 release and save the executable file at /usr/local/bin/docker-compose, which will make this software globally accessible as docker-compose:
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
Next, set the correct permissions so that the docker-compose command is executable:
sudo chmod +x /usr/local/bin/docker-compose
To verify that the installation was successful, you can run:
docker-compose --version

Getting Started
Step 1: Clone the Repository
To follow along, clone the example voting application repository:
git clone https://github.com/dockersamples/example-voting-app.git

Step 2: Explore the docker-compose.yml File
The application consists of multiple services defined in the docker-compose.yml file:
vote: A Python web app for voting
result: A Node.js web app displaying the voting results
worker: A background service to process votes
redis: A Redis service for caching votes
db: A PostgreSQL database to store votes
seed: A service that seeds the database
Below is the key structure of the docker-compose.yml file:
services:
vote:
build:
context: ./vote
target: dev
depends_on:
redis:
condition: service_healthy
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost"]
interval: 15s
timeout: 5s
retries: 3
start_period: 10s
volumes:
- ./vote:/usr/local/app
ports:
- "5000:80"
networks:
- front-tier
- back-tier
result:
build: ./result
entrypoint: nodemon --inspect=0.0.0.0 server.js
depends_on:
db:
condition: service_healthy
volumes:
- ./result:/usr/local/app
ports:
- "5001:80"
- "127.0.0.1:9229:9229"
networks:
- front-tier
- back-tier
worker:
build:
context: ./worker
depends_on:
redis:
condition: service_healthy
db:
condition: service_healthy
networks:
- back-tier
redis:
image: redis:alpine
volumes:
- "./healthchecks:/healthchecks"
healthcheck:
test: /healthchecks/redis.sh
interval: "5s"
networks:
- back-tier
db:
image: postgres:15-alpine
environment:
POSTGRES_USER: "NA"
POSTGRES_PASSWORD: "NA"
volumes:
- "db-data:/var/lib/postgresql/data"
- "./healthchecks:/healthchecks"
healthcheck:
test: /healthchecks/postgres.sh
interval: "5s"
networks:
- back-tier
seed:
build: ./seed-data
profiles: ["seed"]
depends_on:
vote:
condition: service_healthy
networks:
- front-tier
restart: "no"
volumes:
db-data:
networks:
front-tier:
back-tier:
Step 3: Running the Application
To deploy the application using Docker Compose, navigate to the project directory and run:
docker-compose up -d
This command starts all services in detached mode


.
Step 4: Accessing the Application
Voting App: Open
http://localhost:8080
Results App: Open
http://localhost:8081
Step 5: Stopping the Application
To stop the application, run:
docker-compose down

Conclusion
Docker Compose simplifies multi-container application management, making it easy to define, deploy, and scale services. By following this tutorial, you have successfully deployed a multi-container voting application using Docker Compose. Experiment with different configurations and extend the application to match your use cases.
If you found this tutorial helpful, leave a comment on the YouTube video or reach out via GitHub. Happy coding! ๐
