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:
Docker and Docker compose installed
Knowledge of docker-compose and YAML
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---->
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.
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.
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.
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.
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.
Let's get started!
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
Enter inside the directory of repository you cloned in previous step
$ cd Docker-Compose-Project
Then run the$ docker-compose up
command :Access the Poll application on
http://localhost:8501
and make sure you haveport 8501
is open to access the app :Access your result app on
http://localhost:80
:Now do submit your response on Poll app and check the Result app :
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