PLAYING SUPER MARIO BROS ON FARGATE (CONTAINERS SERIES) - #EP 1
Tags: containers, docker, fargate, aws
Published: 2023-01-28 16:55:21


Hi folks, this series will contain several episodes with the goal of explaining how to use a containerized application on AWS in a totally fun way. We’ll cover several compute topics and at the end have a game running on a fargate cluster on AWS. In the current episode, we’ll understand about containerization concepts and some related topics, run the application that we’ll use in our fargate cluster later on our local machine.

<br />

---

<br />
First, let’s understand some concepts that will help us understand containers. We need to talk about the kernel, which is a program that manages the connection between hardware and software. It’s responsible for allowing applications to run, for reading and writing addresses on disk and memory, manages the use of available resources on the machine, responsible for scheduling processes to run, etc.

Each OS has different implementations for their own kernel, but all are responsible for controlling the hardware.

To run an OS inside another it’s necessary to use the hypervisor, which is a a process that enables one or more OS’s to run within a host operating system. In this way, its is function for controlling the access of the OS (virtual machine) to hardware devices.

There are 2 types of hypervisors, the Bare-Metal Hypervisor and the Hosted Hypervisor

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7pz95744et8y5v8fl90o.png)

<br />
In Bare Metal Hypervisor, the software runs directly on the machine’s hardware, running a virtual operating system on top of a hypervisor layer.

In the “Hosted Hypervisor”, virtualization happens when an operating system virtualization program is installed on the machine’s OS,
such as virtualbox.
<br />
<br />

## CGROUPS


![Image by Julia Evans](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bx0rgmlpf33cwxypnruf.png)

<br />
We can’t help but talk about Linux’s control groups, or cgroups, which were created by Googles engineers. We can define cgroups as a Linux kernel tool that isolates and controls resource usage for user processes.

These processes can be placed in namespaces, which resource allocation management per namespace can be used to limit the overall amount of network usage, memory, CPU usage, etc.

The function of namespaces is to make the resources accessed by a process appear to be the only resources the system has, making namespaces an isolation tool for processes that share the same kernel.

The cgroups made possible the creation of the LinuX Containers. It was one of the pillars in the creation of the containers we are currently working on, having an advantage of cgroups and namespace isolation to create a virtual environment with separate process and network space.
<br />
<br />
## CONTAINERS
Containers are like isolated environments within a server, with the objective of separating responsibilities and being able to isolate the processes of each resource.

A container has a group of processes running from an image that provides all the necessary files. Containers share the same kernel and isolate application processes from the rest of the operating system.

Containers have their own filesystem and allocated IP, are very lightweight, and startup and restart tend to be quite fast as there is no need to boot the Kernel every time.


![Image by weave works](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f28uo9axf5ax2bbrwzsk.png)

<br />
A container is not the same thing as a VM. According to [UOL’s blogspot](https://meunegocio.uol.com.br/blog/maquina-virtual-vm-x-containers-diferencas-e-semelhancas/#:~:text=Na%20pr%C3%A1tica%2C%20o%20Container%20promove,e%20depois%20com%20a%20m%C3%A1quina.), a container can share the same operating system kernel, can create isolated environments where different applications can run simultaneously, since the division is made based on available resources, such as memory and processing. A virtual machine, on the other hand, allows a physical machine to host other hardware with a different operating system, hard drive and independence from the original hardware.
<br />
<br />
## DOCKER
Docker is the most widely used container technology today, making it the industry standard tool for containerization.

A Docker container is made up of an image. The base image contains the container’s operating system, which can be different from the host’s operating system, and this image is made up of a few layers.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/neo2tkm60gm3fmfe8yej.png)


<br />
The first layer is the base layer, which becomes responsible for booting, containing the kernel and the bootfs boot sector. This is where the cgroups for process control, namespace and device mapper are created.

The second layer is the one that contains an image base. This rootfs layer can be one or more operating systems.

The last layer is the abstraction layer, has write permission, but modifications are not reflected in the base image, just in the layer which the system visualizes. It is in this layer that the user of the container will work and will be able to create new images.

The docker HUB is a repository with only docker images where we can have access to several ready-to-use images.

To learn more about docker, docker tools, image creation, docker storage systems, [click here.](https://docs.docker.com/)
<br />
<br />
## HANDS ON
Let’s upload our first local container containing the image of our game, which in the future we’ll upload on fargate cluster on AWS.

The first thing is to install Docker. [Click here](https://docs.docker.com/engine/install/) to install. You can check the Docker comands[ HERE](https://docs.docker.com/engine/reference/commandline/docker/).

Next, download the image. We’ll not create the image, it’s already to use at the docker hub.

For that, use the following command:
<br />
```
docker pull pengbai/docker-supermario
```
<br />
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ue0suhcmq2mo8umd7nuc.png)

In the previous command, the docker image was downloaded on your machine, now we’ll run a container with the command below to run this image. Let’s pass the necessary ports as a parameter to up the image.
<br />
```
docker run -d -p 8600:8080 pengbai/docker-supermario
```
<br />
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/66bgs0ldj52byikoo92w.png)

Run with mapping container’s 8080 port, and use your navigator http://localhost:8600
<br />

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nzxkl482ob8kg2elof7q.png)

Now you can play the game locally.

To be continued …