Intro To Python Apis and Docker
Published: 2021-09-12 21:03:54

**Docker** is an open source containerisation platform. Basically, it’s a toolkit that makes it easier, safer and faster for developers to build, deploy and manage containers. Although it began as an open source project, Docker today also refers to Docker, Inc., the company that produces the commercial Docker product. Currently, it is the most popular tool for creating containers, whether developers use Windows, Linux or MacOS.

**Some of the tools and terminology commonly used with Docker include the following:**
Docker Engine: The runtime environment that allows developers to build and run containers.
**Dockerfile**: A simple text file that defines everything needed to build a Docker container image, such as OS network specifications and file locations. It’s essentially a list of commands that Docker Engine will run in order to assemble the image.
**Docker Compose**: A tool for defining and running multi-container applications. It creates a YAML file to specify which services are included in the application and can deploy and run containers with a single command via the Docker CLI.

A **container** is an executable unit of software that packages application code with its dependencies, enabling it to run on any IT infrastructure. A container stands alone; it is abstracted away from the host operating system (OS) — usually Linux — which makes it portable across IT environments.
One way to understand the concept of a container is to compare it to a virtual machine (VM). Both are based on virtualization technologies, but while a container virtualizes an OS, a VM leverages a hypervisor — a lightweight software layer between the VM and a computer’s hardware — to virtualize physical hardware.

**Microservices** is a service-oriented architecture pattern wherein applications are built as a collection of various smallest independent service units. It is a software engineering approach that focuses on decomposing an application into single-function modules with well-defined interfaces. These modules can be independently deployed and operated by small teams that own the entire lifecycle of the service.

**Micro-service Architecture** is an architectural development style that allows building applications as a collection of small autonomous services developed for a business domain. It is a variant of structural style architecture that helps arrange applications as a loosely coupled service collection. The Micro-service Architecture contains fine-grained services and lightweight protocols.

**Introduction to microservices using Python, flask, and docker.**
Flask is super useful for building Microservices. You can utilize any number of it’s built-in extensions to design and deploy Microservices at high velocity. It will help you to get your offerings to market fast.

Note that you can create each service with a different language, one service you can use Javascript Nodejs and expressjs while the other uses flask or FastAPI.

A **monolithic application**,has a single code base with several multiple application packages and modules.

Each module has separate business logic. This type of application has a single build for the entire application and delivered as a single deploy-able.

**Characteristics of Microservice Architecture**
1.Microservices communicate with each other by using well-defined APIs and this implementation is hidden from other microservices. 
-Microservices don’t need to share the same technology stack, libraries, or frameworks.

2.Microservices can be deployed independently and more frequently.
3.Microservices architecture consists of a collection of small services. Each service is self-contained. It implements a single business function. It should do one thing only and do it well.

Credits to @grayhat for explaining this during a bootcamp. 
**Using Docker**
   **note : ** a ** docker image**  is a read-only, inert template that comes with instructions for deploying containers. In Docker, everything basically revolves around images.
An image consists of a collection of files (or layers) that pack together all the necessities—such as dependencies, source code, and libraries—needed to set up a completely functional container environment.

** Code Samples**
FROM python 3.8
 COPY ./src

WORKDIR ./requirements.txt/src/requirements.txt

EXPOSE 5000:5000

RUN pip install -r requirements.txt

CMD [ "python", "app.py"]