Example of application: a webscraping program of press articles with sentiment analysis.
Imagine: Your webscraping project is finally finished! Or almost... You now have an application capable of extracting online press articles and then performing sentiment analysis on their content. You have solved all the compatibility issues between NLP libraries in your virtual environment. Your parsing approach is robust, the sentiment analysis holds up and you are satisfied with the visual output
How to make the world benefit from your invention? On the web of course!
Between a program developed on a local machine and a secure web service accessible to the world, there are a number of steps to consider. The term "deployment" refers to the process required to put an application into service, also called a web service. There are many approaches to deploying a web service. In this series of articles, we will present 3 scenarios:
In this series of articles, we will present 3 scenarios:
Scenario 1: From-scratch approach
Scenario 2: Docker approach
Scenario 3: Serverless approach
Docker is a containerization tool. It allows the virtualization of the operating system in order to provide software and packages contained in containers.
What is a container?
A container is a package of software, it holds all the elements allowing an application to be deployed and to work in any environment.
What is the purpose of a container?
Deploying an application from one environment to another often poses difficulties. For example, an application running in environment A does not necessarily work in environment B because of versioning issues, missing libraries, operating system compatibility, etc.
The container solves these problems by isolating the solution from the rest of the environment in which it is deployed. Thus, when a container is used to deploy an application, the solution becomes portable and system independent.
Like virtual machines, the container system is based on the concept of virtualization.
Virtual machine vs. container?
A virtual machine is a complete copy of a computer with its hardware, resources and operating system.
Inversely, a container contains only the elements necessary for a task or application to function (code, dependencies, configuration, processes, networks, etc.).
Speed vs. Robustness
Because it contains all the components of a real machine including a dedicated kernel, a virtual machine takes longer to start and run than a container.
Containers are much faster, but since they share a single kernel, they are vulnerable if the kernel crashes. Conversely, the kernel of a virtual machine is not affected when another virtual machine crashes.
Portability
On the other hand, virtual machines have limited portability, which is not the case for containers. This characteristic makes the container an ideal tool for hosting a web server or an application programming interface (API).
3 phases
The steps:
docker build -t <docker-name>
docker run -p 5000:8080 <tag-name> or <image-id>
Note: the docker continues to run even after the terminal is closed.
Once the docker is stopped, the data created during the session is lost.
docker volume create <shared-file-name>
Note: docker desktop can help to manage the different running dockers and debugging
Docker compose allows to coordinate the simultaneous creation of different dockers
Example:
To sum up:
Containerization allows the virtualization of the operating system and is therefore different from a virtual machine. Its two greatest strengths are portability and speed. With Docker, the process is divided into three steps: the dockerfile, the image and the container. In a future article, we will discuss the third and final deployment approach: the serverless approach.
Stay tuned…