Docker Project for DevOps Engineers

Docker Project for DevOps Engineers

#90 Days of DevOps Challenge

Microservice vs Monolithic in Docker

Monolithic:-

A monolithic architecture is a traditional model of a software program, which is built as a unified unit that is self-contained and independent from other applications. The word “monolith” is often attributed to something large and glacial, which isn’t far from the truth of a monolith architecture for software design. A monolithic architecture is a singular, large computing network with one code base that couples all of the business concerns together. To make a change to this sort of application requires updating the entire stack by accessing the code base and building and deploying an updated version of the service-side interface. This makes updates restrictive and time-consuming.

Advantages:-

  • Simple to develop

  • Simple to deploy one binary

  • Easy Debugging & Error tracing

  • Simple to test

  • Less Costly

Disadvantages:-

  • Difficult to understand and modify

  • Tightly coupled

  • Higher start up and load times

  • Redeploy the entire application on each update, and also continuous deployment is difficult

  • Less reliable: A single bug can bring down the entire application.

  • Scaling the application is difficult

  • Difficult to adopt new and advanced technology: Since changes in frameworks or languages will affect an entire application

Microservice:-

Microservices (or microservices architecture) is a cloud-native architectural approach in which a single application is composed of many loosely coupled and independently deployable smaller components, or services.

Advantages:-

  • Decoupled

  • Ensures continuous delivery and deployment of large, complex applications.

  • Better testing since services are smaller and faster to test.

  • Better deployments each service can be deployed independently.

  • No long term commitment to technology when developing a new service, you can start with a new technology stack.

Disadvantages:-

  • Slow bootup times of VMs

  • Increased memory consumption

  • Large OS footprint

  • Initial Costs are very High and this type of architecture demands for proficiency in the skills of the developers.

  • Testing is difficult and time consuming because there is an additional complexity involved because of the distributed system.

  • Deployment Complexity there is added operational complexity of deploying and managing a system that contains various service types.

Project on Microservices

Step 1:- Need to clone the project by the below command

git clone https://github.com/Saikat55/microservices-k8s.git

Step 2:- Now we need to create a Docker file for creating an image

FROM python:alpine3.7
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
ENV PORT 5000
EXPOSE 5000
ENTRYPOINT [ "python" ]
CMD [ "app.py" ]

Step 3:- We have created a docker file now we need to create a docker image by using the docker file

 docker build . -t flask-api:latest

Step 4:- Now we can verify the images by using the below command

docker images

Step 5:- Now using that mage we can create n number of container

 docker run -d -p 5000:5000 flask-api:latest

Step 6:- Now we need to search in the web browser along with the ipv4 address and port number

Step 7:- Now we can test the API using Postman. in the scenario, we need to install Postman locally using to test the API. We can download postman by using the below link

https://www.postman.com/downloads/

Step 8:- Open the Postman application. Click on + and create a new Collection, rename the collection to "Flask API"

Step 9:- Now need to Add a request and need to Choose to Get and provide the Public IPv4:port and click on Send. Now we can see the expected output in the below terminal.

Step 10:- We need to create a Duplicate Get Task and provide the same URL <Ip_port_URL>/tasks click on Send. In the below, we will receive an error message "500 Internal Server Error"

Step 11:- To fix the error we have to create a database so it acts as a backend and before that need to create a custom bridge network so that the container can connect with it.

By using the below command we can create a custom network

# using the below command we can create a custom network
docker network create mongo-flask
# Using below command we can get the list of all network(default & custom)
docker network ls

Step 12:- Now we need to kill the existing container and start back using the custom network

docker run -d -p 5000:5000 --network mongo-flask flask-api:latest

**Step 13:-**Need to create a database as a backend and we will be using Mongo. By using the below command we will install Mongo

docker run -d -p 27017:27017 --network mongo-flask --name mongo mongo:latest

Step 14 :- Now need to open Postman and try to send the URL. We can see, the below page is rerouting.

Step 15:- We can use the docker-compose to automate the task. in that case we no need to create a custom network for the container. As docker will automatically map

# Install the docker-compose
sudo apt-get install docker-compose -y

version: '3.9'
services:
  flask-api:
    image: https://github.com/Saikat55/microservices-k8s.git
    container_name:flask-micro-api
    ports:
      -"5000:5000"
  mongo-db:
    image: mongo
    container_name: mongo
    ports:
      -"27017:27017"

 # docker-compose up -d
 # docker-compose down

Step 16:- Now we will push that image to the docker hub. before that, we need to tag the image name

# Using below command we need to login to docker hub before pushing image
docker login
# Using beow command we need to tag that image
docker tag flask-api:latest saikat55mukherjee/flask-api:latest
# we can push that image to the docker hub
docker push saikat55mukherjee/flask-api:latest

Finally !! we have successfully deployed the Microservices app using Docker.

Devops#devops,#90daysofDevOps

Thank you for reading!! I hope you find this article helpful!!

if any queries or corrections to be done to this blog please let me know.

Happy Learning!!

Saikat Mukherjee

Did you find this article valuable?

Support Saikat Mukherjee's blog by becoming a sponsor. Any amount is appreciated!