Docker Compose  Project: Deploy Multi-Container Application with 5 Different Services

Docker Compose Project: Deploy Multi-Container Application with 5 Different Services

Deploying a multi-container application can be a complex process, especially when done manually. Without a Docker compose, we would have to manually create and configure each container, specify network connections and dependencies, the container's startup sequence, and define health checks. This can be a time-consuming and error-prone process. However, using Docker Compose streamlines the process, making it easier to build and manage multi-container applications.

In this blog post, We'll learn how to deploy a multi-container application using a docker-compose.yml file through my Docker-Compose project. We'll be building three containers from Dockerfile and two containers from official Docker images. Each container also has a health check that helps ensure the application is running correctly.

Pre-requisites:

  1. Docker and Docker compose installed

  2. Knowledge of docker-compose and YAML

  3. Basic understanding of Python and Javascript languages

Project Overview:

This project is a web application designed to create a poll for the Popular Container Orchestration Tool using the Vote app [Python-based]. The application collects user choices and stores them on a Redis server. A Worker app [Python-based] then collects the data from the Redis server, processes the data to create poll results, and stores the result data in a Postgres database server. Finally, the Result app [NodeJs] retrieves data from the Postgres server and displays the poll results. This application provides an interface to conduct polls, and with the help of Docker Compose, it deploys multiple containerized services, making it a scalable and efficient solution for conducting polls.

Let's understand in brief how these five containers work with each other to process the User data---->

  1. Vote App: This App is built in Python and uses the Streamlit and Redis libraries. It hosts a web application to collect poll data and connects to the Redis server to direct that data.

  2. Redis: It is a key-value store used to store and retrieve data. This Redis container takes Poll entries by the user and stores them in-memory cache to use further.

    Spring Caching with Redis. What is Redis? How can we use Redis for… | by  Vinesh | Javarevisited | Medium

  3. Worker App: This App is built in Python and uses the Redis and psycopg2 libraries. It collects the poll data from the Redis server, processes the data to create poll results, and directs the result data to a Postgres database server.

  4. Postgres DB: It is used as the primary data store or data warehouse for many web, mobile, geospatial, and analytics applications. The poll result from the Worker app is stored in this container. Postgres can handle databases ranging from a few gigabytes to several terabytes in size.

    Postgres Handles More Than You Think

  5. Result App: This App is built in Javascript and uses the express and pg libraries. It connects to the Postgres database server to retrieve that result data and hosts a web application to show poll results.

Now we are going to deploy all these apps/services with one click using Docker-compose.

What is Docker Compose: Example, Benefits and Basic Commands | Simplilearn

Let's get started!

  1. Create a docker-compose.yml file for five containers to provision them, allow inter-connectivity [-networks] and dependability [-depends_on] amongst them.

    Get the source code here:

    $ git clone https://github.com/Chaitannyaa/Docker-Compose-Project.git

  2. Enter inside the directory of repository you cloned in previous step $ cd Docker-Compose-Project Then run the $ docker-compose up command :

  3. Access the Poll application on http://localhost:8501 and make sure you have port 8501 is open to access the app :

  4. Access your result app on http://localhost:80 :

  5. Now do submit your response on Poll app and check the Result app :

  6. Do check networks $ docker network ls and also health of all your running containers $ docker ps

Now you can remove all these containers in 1 click, Type $ docker-compose down

Thank you for reading the full blog with patience!

Summary:

This blog post describes the deployment of a multi-container application by using the docker-compose.yml file for a project that comprises five services: Redis, PostgresDB, Vote, Worker, and Result. This multi-container application project demonstrates the power of using Docker Compose for deploying complex applications. By leveraging the containerization technology provided by Docker, the application can be easily managed and scaled to meet the needs of a growing user base. Additionally, the use of health-checks helps ensure that the application is running correctly.

I hope you learned something new today with me!

Stay tuned for my next blog on "Docker Swarm". I will keep sharing my learnings and knowledge here with you.

Let's learn together! I appreciate any comments or suggestions you may have to improve my blog content.

Thank you,

Chaitannyaa Gaikwad

(19) Chaitannyaa Gaikwad | LinkedIn

Did you find this article valuable?

Support Chaitannyaa Gaikwad by becoming a sponsor. Any amount is appreciated!