# 11.11 ECS - Part 1 - What is Docker

## ECS

Elastic Container Service / EC2 Container Service.

## Typical Application Stack

An application that is running on a traditional virtual machine is looks like this:

![](https://2556340799-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M5zQ5aJ_upQQkYs7m_V%2Fsync%2Ff145964d175201b213bf84343c6306dfb0855b90.png?generation=1588054533174304\&alt=media)

## Terms:

* Guest OS: Like Linux, etc.
* Dependencies: built on top of the OS. Like Apache httpd server, PHP, MySQL, etc.
* Applications: relies on the dependencies. Like a simple form webpage on a PHP website.

The dependencies of the above PHP website could be Apache httpd server, PHP, MySQL. These dependencies may have different versions which makes the scaling out to be difficult, because you need to deploy these dependencies on a fleet of servers and manage the version of them.

Docker is designed to wrap up all your dependencies so that they are all the same. So it is doesn't matter which EC2 instance or which virtual machine or physical machine you deploy them on, the environment will always be the same.

## What is Docker

* Docker is a software platform that allows you to build, test, and deploy applications quickly.
* Docker is **highly reliable**: you can quickly deploy and scale applications into any environment and know your code will run.
* Docker is **infinitely scalable**: Running Docker on AWS is a great way to run distributed applications at any scale.
* Docker packages software into standardized units called **Containers**:
  * Containers allow you to easily package an application's code, configurations, and dependencies into easy to use building blocks that deliver environmental consistency, operational efficiency, developer productivity, and version control.

## Virtualization vs. Containerization

![](https://2556340799-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M5zQ5aJ_upQQkYs7m_V%2Fsync%2Fcaedf90b66945a8ba02e6d91a82703c943e8c78d.png?generation=1588054533120998\&alt=media)

## Containerization Benefits

* Escape from dependency hell
* Consistent progression from DEV -> TEST -> QA -> PROD
* Isolation - performance or stability issues with App A in Container A, won't impact App B in Container B.
* Much better resource management.
* Extreme code portability
* Allows you to start Micro-Services.

## Docker Components

* Docker Image:&#x20;
  * Think it like an "ISO" or an "AMI", only have the files that can boot a container.
  * An Image is a read-only template with instructions for creating a Docker Container. It contains:
    * An ordered collection of root file system changes and the corresponding execution parameters for use within a container runtime.
  * An Image is created from a DockerFile, a plain text file that specifies the components that are to be included in the container.
  * Images are stored in a Registry, such as DockerHub or AWS ECR.
* Docker Container:&#x20;
  * This is everything that is needed for an application to run. Container can be run, started, stopped, moved, and deleted. Each container is an isolated and secure application platform.
  * Containers are a method of operating system virtualization that allow you to run an application and its dependencies in resource-isolated processes.
  * Containers have everything the software needs to run - including libraries, system tools, code, and runtime.
  * Containers are created from a read-only template called an Image.
* Layers / Union File System:&#x20;
  * Image is read-only template from which containers are launched. Each image consists of a series of Layers and Docker makes use of the Union File System to combine these layers into a single image. Union File Systems allow files and directories of separate file systems known as branches to be transparently overlayed forming a single coherent file system. One of the reasons that Docker is so lightweight is these layers. When you change a docker image, for example update an application to a new version, a new layer will be built and rather than replacing the whole image or entirely rebuilding as you may do with a virtual machine. Only that layer is added or updated. So now you don't need to distribute a whole new image to do the update. You can just push out a new layer and this makes distributing docker image files much faster and simpler.&#x20;
* DockerFile:&#x20;
  * It is the images that then built from these base images using a simple and descriptive set of instructions. Instructions creates a new layer in our image. Instructions includes actions like run a command or add a file or add a directory or create an environment variable. And these instructions are stored in a file called a DockerFile, and docker reads this DockerFile when you request to build an image and then executes instructions and return a final image.&#x20;
* Docker Daemon/Engine:&#x20;
  * This is a docker engine runs on Linux in order to create the operating environment for your distributed application, and the in-host daemon communicates with the Docker Client to execute commands to build ship and run containers.
* Docker Client: &#x20;
  * This is the interface between you and the docker engine and it allows creation, manipulation, deletion of docker containers and control of the docker daemon.&#x20;
* Docker Registries / Docker Hub:&#x20;
  * It holds these images and these images are public or private stores from which you upload or download your images, and the public docker registry is provided with the docker hub, and it serves a huge collection of existing images for you to use. And these could be images that you create yourself or you can use images that others created.&#x20;

## AWS ECS

Amazon EC2 Container Service (ECS), is a highly scalable, fast, container management service that makes it easy to run, stop, and manage Docker containers on a cluster of EC2 instances. Amazon ECS lets you launch and stop container-based applications with simple API calls, allows you to get the state of your cluster from a centralized service, and gives you access to many familiar Amazon EC2 features.

ECS is the "Amazon's managed version" of Docker.
