# DS-project1. Report
## Introduction
The task is to create a cluster for deploying an application.
The web application will be called **The Red Button**.
The idea of the application: you will get a dilemma, you can agree on the condition and press the red button, or can skip it. Anyway you will get a statistic for this dilemma (number of people who agreed on the suggested condition and number of people who skipped).
## Understanding Docker-machine and Docker Swarm deployment
**1.** *What is Docker-machine and what is it used for?*
**Docker machine** - the tool to create a remote virtual machine (VM) easily and manage those containers.
**It is used to** control docker engine of a virtual machine remotely. It allows to update docker engine, stop VM, view state.
**2.** *What is Docker Swarm, what is it used for and why is it important in Containers Orchestration?*
**Docker Swarm** is a group of virtual or physical machines that run Docker application and form together one cluster.
**It is used for** container orchestration and to magane multiple containers in multiple machines.
**It is important** because of its high level of availability offered for applications. It allow developers to manage high amount of nodes in a single ecosystem.
**3.** - *Docker Machine, Master*
*create master*

**4.** - *Workers*
*create workers*
*1st worker*

*2nd worker*

***docker-machine ls** - there are 3 running machines*

*with this command we can get info about currently running machines, their ips and their state*
## Container Docker Cluster farm deployment
**5.**
*docker swarm* initialized on master node

*by using the command from the output of creation swarm we join two more machines to that swarm as workers*
***docker node ls** - observe their states, how they are connected, and the leader - Master node**

*Here we see, that we have one manager node and three workers - all are ready and active.*
*We can use IPs of workers and master to get visualizer picture. On that step the main problem is that web service did not run*

*There is a problem that only master is involved*

*Correct visualization will be provided later*
**6.**
Docker can be promoted to Master when manager role becomes unavailable. Vice versa action can be done as well.
It can be done with
```
docker node promote
docker node demote
```
It can be done only on manager node.
Because of the fact, that all machines are run on out machine, we can easily get into VMs via ssh and explicitly and initialize docker swarm on master machine. Also, we have option, that specify that if node is down docker should reboot it at that time.
**7.**
We can observe hostname and host node where web page is running and it spread across the server.

**8.**
Yes it can not be done automatically. Docker Swarm does not support it.
Scaling can be done manually with Docker CLI.
```
docker service scale <SERVICE-ID>=<NUMBER-OF-TASKS>
```
But, we can set value *replicas* in docker-compose for every service that we want to scale.
# Docker Container migration - Application Distribution
**9.**




*We can obserce here that when node is goes down services that were in this node will be distributed to other nodes. And back again when the node will come back to live.*
**10.** *Update in web-app*
When some changes are made in the application we have to restart our container.
**11.**
It can be done with both CLI and GUI (example above).
We can do
```
docker node ls
```
and as an example we can observe active nodes.
# Playing with memory
**12.**
**OOME** it is when we do not have enough memory to run service.
This issue will slow down the work of an application.
With the help of Docker Swarm services will be distributed to another node from the one, which do not have enough memory.
**13.**
We have done it with putting in Docker Compose limite for CPU (15%).


# Compression
**14.**

*The limite of size of images are 50M*
This size can be reduces by decreasing the calue of memory limite in docker compose.
* Use a smaller base image.
* Don't install debug tools like vim/curl.
* Minimize Layers.
* Use — no-install-recommends on apt-get install.
* Add rm -rf /var/lib/apt/lists/* to same layer as apt-get installs.
[web site with tips](https://hackernoon.com/tips-to-reduce-docker-image-sizes-876095da3b34)
# Web application
**15.**
Owr web application - **the red button**:
Used:
* Flask
* Python
* Mongo
* Html
* Css
* JS
*The idea:* you will get an dilemma, you can agree on the condition and press **the red button**, or can skip it. Anyway you will get a statistic for this dilemma, number of people who agreed on the suggested condition and number of people who skipped.



[GitHub repository](https://github.com/MaEvGoR/red_button_project.git)
## Conclusion
We have learn the following things: we can start VM by ```docker-machine```; we can create clusters of machines by ```docker swarm``` which will distribute a load; we can set setting for deploying in docker compose.
We have met the following difficulties: find out convenient properties to run services; to deal with diffrences between container, service, node, server, image and etc.
###### Maksim Evgrafov - BS-18-DS-01
###### Idel Ishbaev - BS-18-SE-02